forked from isis-project/BrowserAdapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrowserAdapter.h
695 lines (580 loc) · 31.2 KB
/
BrowserAdapter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
/* @@@LICENSE
*
* Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
LICENSE@@@ */
#ifndef BROWSERADAPTER_H
#define BROWSERADAPTER_H
#include "BrowserClientBase.h"
#include "AdapterBase.h"
#include "KineticScroller.h"
#include <glib.h>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <pbnjson.hpp>
#include <semaphore.h>
#include <BrowserRect.h>
#include "BrowserScrollableLayer.h"
#include <QImage>
#include <QPainter>
struct PluginType;
class BrowserOffscreen;
struct BrowserAdapterData;
class BrowserSyncReplyPipe;
class BrowserAdapterData;
class BrowserCenteredZoom;
struct BrowserMetaViewport;
/**
* This is the NPAPI browser plugin to our browser. This object communicates with
* the browser server which renders a browser page into this adapter.
*
* All js_* methods are the implementations of the exposed JavaScript routines
* callable by a JavaScript program.
*
* The msg* methods are unsolicited messages sent by the browser server when it
* needs to inform this adapter of something.
*
* The handle* methods are called by the browser via the AdapterBase::PrvNPP_HandleEvent
* NPAPI plugin callback event handler.
*/
class BrowserAdapter : public BrowserClientBase
, public AdapterBase
, public KineticScrollerListener
{
public:
BrowserAdapter(NPP instance, GMainContext *ctxt, int16_t argc, char* argn[], char* argv[]);
virtual ~BrowserAdapter();
void freeze();
void thaw();
bool isFrozen();
bool flashGestureLock() const {
return mFlashGestureLock;
}
// Methods exposed to JavaScript:
static const char* js_addUrlRedirect(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_clearHistory(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_clickAt(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_deleteImage(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_generateIconFromFile(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_getHistoryState(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_goBack(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_goForward(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_interrogateClicks(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_openURL(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_pageScaleAndScroll(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_reloadPage(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_resizeImage(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_saveViewToFile(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_selectPopupMenuItem(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_sendDialogResponse(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setMagnification(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setMinFontSize(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setPageIdentifier(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_smartZoom(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setViewportSize(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_stopLoad(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_gestureStart(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_gestureChange(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_gestureEnd(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_scrollStarting(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_scrollEnding(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setEnableJavaScript(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setBlockPopups(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setHeaderHeight(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setAcceptCookies(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setShowClickedLink(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_mouseEvent(AdapterBase* adapter, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const char* js_addElementHighlight(AdapterBase* adapter, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const char* js_removeElementHighlight(AdapterBase* adapter, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const char* js_connectBrowserServer(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_disconnectBrowserServer(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_pageFocused(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_inspectUrlAtPoint(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_isEditing(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_insertStringAtCursor(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_enableSelectionMode(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_disableSelectionMode(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_clearSelection(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_saveImageAtPoint(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_getImageInfoAtPoint(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_selectAll(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_cut(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_copy(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_paste(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_interactiveAtPoint(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_getElementInfoAtPoint(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setMouseMode(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_startDeferWindowChange(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_stopDeferWindowChange(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setSpotlight(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_removeSpotlight(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setHTML(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_disableEnhancedViewport(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_ignoreMetaTags(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setNetworkInterface(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_enableFastScaling(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setDefaultLayoutWidth(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_printFrame(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_skipPaintHack(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_findInPage(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char *js_mouseHoldAt(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_handleFlick(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setVisibleSize(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const char* js_setDNSServers(AdapterBase *adapter, const NPVariant *args, uint32_t argCount, NPVariant *result);
static const int kRecordBufferEmptyError = -10;
static const int kExceptionMessageLength = 128;
protected:
// AdapterBase overrides:
virtual bool handlePenDown(NpPalmPenEvent *event);
virtual bool handlePenUp(NpPalmPenEvent *event);
virtual bool handlePenMove(NpPalmPenEvent *event);
virtual bool handlePenClick(NpPalmPenEvent *event);
virtual bool handlePenDoubleClick(NpPalmPenEvent *event);
virtual bool handleKeyDown(NpPalmKeyEvent *event);
virtual bool handleKeyUp(NpPalmKeyEvent *event);
virtual bool handleTouchStart(NpPalmTouchEvent *event);
virtual bool handleTouchEnd(NpPalmTouchEvent *event);
virtual bool handleTouchMove(NpPalmTouchEvent *event);
virtual bool handleTouchCancelled(NpPalmTouchEvent *event);
virtual bool handleGesture(NpPalmGestureEvent *event);
virtual void handlePaint(NpPalmDrawEvent* event);
virtual void handleWindowChange(NPWindow* window);
virtual bool handleFocus(bool val);
// KineticScrollerListener overrides:
virtual void scrollTo(int x, int y);
virtual void startedAnimating();
virtual void stoppedAnimating();
// BrowserClientBase overrides:
virtual void serverConnected();
virtual void serverDisconnected();
// Async message handlers inherited from BrowserClientBase:
virtual void msgPainted(int32_t sharedBufferKey);
virtual void msgReportError(const char* url, int32_t code, const char* msg);
virtual void msgContentsSizeChanged(int32_t width, int32_t height);
virtual void msgScrolledTo(int32_t contentsX, int32_t contentsY);
virtual void msgLoadStarted();
virtual void msgLoadStopped();
virtual void msgLoadProgress(int32_t progress);
virtual void msgLocationChanged(const char* uri, bool canGoBack, bool canGoForward);
virtual void msgTitleChanged(const char* title);
virtual void msgTitleAndUrlChanged(const char* title, const char* url, bool canGoBack, bool canGoForward);
virtual void msgDialogAlert(const char* syncPipePath, const char* msg);
virtual void msgDialogConfirm(const char* syncPipePath, const char* msg);
virtual void msgDialogSSLConfirm(const char* syncPipePath, const char* host,int32_t code, const char* certFile);
virtual void msgDialogPrompt(const char* syncPipePath, const char* msg, const char* defaultValue);
virtual void msgDialogUserPassword(const char* syncPipePath, const char* msg);
virtual void msgActionData(const char* dataType, const char* data);
virtual void msgDownloadStart(const char* url);
virtual void msgDownloadProgress(const char* url, int32_t totalSizeSoFar, int32_t totalSize);
virtual void msgDownloadError(const char* url, const char* errorMsg);
virtual void msgDownloadFinished(const char* url, const char* mimeType, const char* tmpFilePath);
virtual void msgLinkClicked(const char* url);
virtual void msgMimeHandoffUrl(const char* mimeType, const char* url);
virtual void msgMimeNotSupported(const char* mimeType, const char* url);
virtual void msgCreatePage(int32_t identifier);
virtual void msgClickRejected(int32_t counter);
virtual void msgPopupMenuShow(const char* identifier, const char* menuDataFileName);
virtual void msgPopupMenuHide(const char* identifier);
virtual void msgSmartZoomCalculateResponseSimple(int32_t pointX, int32_t pointY, int32_t left, int32_t top, int32_t right, int32_t bottom, int fullscreenSpotlightHandle);
virtual void msgFailedLoad(const char* domain, int32_t errorCode, const char* failingURL, const char* localizedDescription);
virtual void msgSetMainDocumentError(const char* domain, int32_t errorCode, const char* failingURL, const char* localizedDescription);
virtual void msgEditorFocused(bool focused, int32_t fieldType, int32_t fieldActions);
virtual void msgDidFinishDocumentLoad();
virtual void msgUpdateGlobalHistory(const char* url, bool reload);
virtual void msgPurgePage();
virtual void msgInspectUrlAtPointResponse(int32_t queryNum, bool succeeded, const char* url, const char* desc, int32_t rectWidth, int32_t rectHeight, int32_t rectX, int32_t rectY);
virtual void msgGetHistoryStateResponse(int32_t queryNum, bool canGoBack, bool canGoForward);
virtual void msgIsEditing(int32_t queryNum, bool isEditing);
virtual void msgUrlRedirected(const char* url, const char* userData);
virtual void msgMetaViewportSet(double initialScale, double minimumScale, double maximumScale, int32_t width, int32_t height, bool userScalable);
virtual void msgHighlightRects(const char* rectsArrayJson);
virtual void msgSaveImageAtPointResponse(int32_t queryNum, bool succeeded, const char* filepath);
virtual void msgGetImageInfoAtPointResponse(int32_t queryNum, bool succeeded, const char* baseUri, const char* src,
const char* title, const char* altText, int32_t width, int32_t height, const char* mimeType);
virtual void msgGetElementInfoAtPointResponse(int32_t queryNum, bool succeeded, const char* element, const char* id,
const char* name, const char* cname, const char* type, int32_t left, int32_t top, int32_t right, int32_t bottom, bool isEditable);
virtual void msgMakePointVisible(int32_t x, int32_t y);
virtual void msgIsInteractiveAtPointResponse(int32_t queryNum, bool interactive);
virtual void msgCopiedToClipboard();
virtual void msgPastedFromClipboard();
virtual void msgRemoveSelectionReticle();
virtual void msgCopySuccessResponse(int32_t queryNum, bool success);
virtual void msgPluginFullscreenSpotlightCreate(int32_t spotlightHandle, int32_t rectX, int32_t rectY, int32_t rectWidth, int32_t rectHeight);
virtual void msgPluginFullscreenSpotlightRemove();
virtual void msgSpellingWidgetVisibleRectUpdate(int32_t rectX, int32_t rectY, int32_t rectWidth, int32_t rectHeight);
virtual void msgHitTestResponse(int32_t queryNum, const char *hitTestResultJson);
virtual void msgAddFlashRects(const char* rectsArrayJson);
virtual void msgRemoveFlashRects(const char* rectsArrayJson);
virtual void msgShowPrintDialog();
virtual void msgGetTextCaretBoundsResponse(int32_t queryNum, int32_t left, int32_t top, int32_t right, int32_t bottom);
virtual void msgUpdateScrollableLayers(const char* json);
private:
/* TODO: We should get this from the webkit headers */
enum InteractiveRectType {
InteractiveRectDefault,
InteractiveRectPlugin //< Interactive rect is a plugin rect
};
struct Point {
Point(int x, int y) {
this->x = x;
this->y = y;
}
Point(const Point& rhs) : x(rhs.x), y(rhs.y) {}
void set(int x, int y) {
this->x = x;
this->y = y;
}
bool operator==(const Point& rhs) const {
return x == rhs.x && y == rhs.y;
}
Point& operator=(const Point& rhs) {
x = rhs.x;
y = rhs.y;
return *this;
}
int x;
int y;
};
struct BrowserServerCallArgs {
BrowserServerCallArgs(int queryNum) : m_queryNum(queryNum) {}
virtual ~BrowserServerCallArgs() {}
int m_queryNum; ///< The query number used to associate the reply with the correct call.
};
/**
* We save arguments to inspectUrlAtPoint in this object so that when we receive
* the response we can handle it properly.
*/
struct InspectUrlAtPointArgs : public BrowserServerCallArgs {
int m_x; ///< The orginally supplied X coordinate.
int m_y; ///< The originally supplied Y coordinate.
NPObject* m_successCb; ///< The success callback function.
InspectUrlAtPointArgs(int x, int y, NPObject* cb, int queryNum);
virtual ~InspectUrlAtPointArgs ();
};
struct GetImageInfoAtPointArgs : public BrowserServerCallArgs {
int m_x; ///< The orginally supplied X coordinate.
int m_y; ///< The originally supplied Y coordinate.
NPObject* m_callback; ///< The success callback function.
GetImageInfoAtPointArgs(int x, int y, NPObject* cb, int queryNum);
virtual ~GetImageInfoAtPointArgs ();
};
struct IsInteractiveAtPointArgs : public BrowserServerCallArgs {
int m_x; ///< The orginally supplied X coordinate.
int m_y; ///< The originally supplied Y coordinate.
NPObject* m_callback; ///< The success callback function.
IsInteractiveAtPointArgs(int x, int y, NPObject* cb, int queryNum);
virtual ~IsInteractiveAtPointArgs ();
};
struct GetElementInfoAtPointArgs : public BrowserServerCallArgs {
int m_x; ///< The orginally supplied X coordinate.
int m_y; ///< The originally supplied Y coordinate.
NPObject* m_callback; ///< The success callback function.
GetElementInfoAtPointArgs(int x, int y, NPObject* cb, int queryNum);
virtual ~GetElementInfoAtPointArgs ();
};
struct GetHistoryStateArgs : public BrowserServerCallArgs {
NPObject* m_successCb; ///< The success callback function.
GetHistoryStateArgs(NPObject* cb, int queryNum);
virtual ~GetHistoryStateArgs ();
};
struct IsEditingArgs : public BrowserServerCallArgs {
NPObject* m_callback; ///< js callback fired when reply is ready
IsEditingArgs(NPObject* callback, int queryNum);
virtual ~IsEditingArgs();
};
struct CopySuccessCallbackArgs : public BrowserServerCallArgs {
NPObject* m_callback; ///< js callback fired when reply is ready
CopySuccessCallbackArgs(NPObject* callback, int queryNum);
virtual ~CopySuccessCallbackArgs();
};
struct SaveImageAtPointArgs : public BrowserServerCallArgs {
int m_x; ///< The orginally supplied X coordinate.
int m_y; ///< The originally supplied Y coordinate.
NPObject* m_callback; ///< js callback fired when reply is ready
SaveImageAtPointArgs(int x, int y, NPObject* cb, int queryNum);
virtual ~SaveImageAtPointArgs();
};
struct HitTestArgs : public BrowserServerCallArgs {
const char *m_type;
Point m_pt;
int m_modifiers;
HitTestArgs(const char *type, const Point& pt, int modifiers, int queryNum);
virtual ~HitTestArgs();
};
struct GetTextCaretArgs : public BrowserServerCallArgs {
NPObject *m_callback;
GetTextCaretArgs(NPObject *cb, int queryNum);
virtual ~GetTextCaretArgs();
};
struct UrlRedirectInfo {
std::string re;
bool redir;
std::string udata;
int type;
UrlRedirectInfo( const char* urlRe, bool redirect, const char* userData, int redirectType ) :
re(urlRe), redir(redirect), udata(userData), type(redirectType) {}
};
struct SelectionReticleInfo {
QImage* surface;
GSource* timeoutSource;
int x;
int y;
int centerOffsetX;
int centerOffsetY;
bool show;
};
/**
* A collection of arguments that have been used for a call into BrowserServer that we're waiting
* for a reply on.
*/
template<typename T>
class ArgList
{
private:
typedef std::list<T*> myArgList;
public:
~ArgList() {
typename myArgList::const_iterator i;
for (i = m_args.begin(); i != m_args.end(); ++i) {
delete *i;
}
}
/**
* Add an argument object to this list. We now own the pointer.
*/
void add(T* arg) {
m_args.push_back(arg);
}
/**
* Find an argument object whose query number matches the one provided.
* <strong>The caller now owns the argument object.</strong>
*/
T* get(int queryNum) {
typename myArgList::iterator i;
for (i = m_args.begin(); i != m_args.end(); ++i) {
T* args = *i;
if (args->m_queryNum == queryNum) {
m_args.erase(i); // Caller now owns this pointer
return args;
}
}
return NULL; // Not found
};
private:
myArgList m_args;
};
KineticScroller* mScroller;
QImage* mDirtyPattern;
Point m_pageOffset; // Position of top left corner relative to a Netscape page
Point m_touchPtDoc; // last touch press or touch move point in document coordinates
// viewport size
int mViewportWidth;
int mViewportHeight;
double mZoomLevel;
bool mZoomFit;
int mPageWidth;
int mPageHeight;
int mContentWidth;
int mContentHeight;
Point mScrollPos;
bool mInGestureChange;
BrowserMetaViewport* mMetaViewport;
BrowserCenteredZoom* mCenteredZoom;
BrowserOffscreen* mOffscreen0;
BrowserOffscreen* mOffscreen1;
BrowserOffscreen* mOffscreenCurrent;
QImage* mFrozenSurface;
bool mFrozen;
Point mFrozenRenderPos;
int mFrozenRenderWidth;
int mFrozenRenderHeight;
float mFrozenZoomFactor;
bool m_passInputEvents;
bool mFirstPaintComplete; ///< Set once the first non-empty paint has been completed.
bool mEnableJavaScript;
bool mBlockPopups;
bool mAcceptCookies;
bool mShowClickedLink;
int m_defaultLayoutWidth;
bool mBrowserServerConnected; ///< Is this adapter currently connected to the BrowserServer?
bool mNotifiedOfBrowserServerDisconnect; ///< Has our owner been notified of a BrowserServer disconnect?
bool mSendFinishDocumentLoadNotification; ///< True when load is complete but didFinishDocumentLoad not sent
std::list<UrlRedirectInfo*> m_urlRedirects; ///< an ordered list of URL's to redirect back to the app
int16_t mArgc; ///< Saved copy of argc when adapter is initialized
char** mArgn; ///< Saved copy of argn when adapter is initialized
char** mArgv; ///< Saved copy of argv when adapter is initialized
bool mPaintEnabled;
bool mInScroll;
bool bEditorFocused; ///< Is the current page focused.
bool m_useFastScaling;
double m_startingZoomLevel;
int32_t mPageIdentifier;
ArgList<InspectUrlAtPointArgs> m_inspectUrlArgs;
ArgList<GetHistoryStateArgs> m_historyStateArgs;
ArgList<IsEditingArgs> m_isEditingArgs;
ArgList<GetImageInfoAtPointArgs>m_getImageInfoAtPointArgs;
ArgList<IsInteractiveAtPointArgs>m_isInteractiveAtPointArgs;
ArgList<SaveImageAtPointArgs> m_saveImageAtPointArgs;
ArgList<GetElementInfoAtPointArgs> m_getElementInfoAtPointArgs;
ArgList<CopySuccessCallbackArgs> m_copySuccessCallbackArgs;
ArgList<HitTestArgs> m_hitTestArgs;
ArgList<GetTextCaretArgs> m_getTextCaretArgs;
int mBsQueryNum;
bool m_interrogateClicks;
int mMouseMode;
bool mLogAlertMessages;
bool mPageFocused; ///< Is the onwer of this adapter focused?
bool mServerConnectedInvoked; // has successfully invoked serverConnected
bool mServerConnectedInvoking; // in calling serverConnected
bool mShowHighlight;
std::vector<BrowserRect> mHighlightRects;
Point mLastPointSentToFlash;
bool mMouseInFlashRect;
bool mFlashGestureLock;
typedef std::map<uintptr_t, BrowserRect> RectMap;
typedef std::pair<uintptr_t, BrowserRect> RectMapItem;
RectMap mFlashRects;
bool mMouseInInteractiveRect;
RectMap mDefaultInteractiveRects;
BrowserScrollableLayerMap mScrollableLayers;
BrowserScrollableLayerScrollSession mScrollableLayerScrollSession;
SelectionReticleInfo mSelectionReticle;
static gboolean removeSelectionReticleCallback(gpointer arg);
// the highlight area (mouse, gesture are directly send to it)
int m_spotlightHandle;
int m_spotlightAlpha; // 0~ 255
BrowserRect m_spotlightRect;
pbnjson::JSchemaFile m_hitTestSchema;
bool init();
bool initializeIpcBuffer();
void setDefaultViewportSize();
void sendStateToServer();
// gesture handling
void doGestureStart(int cx, int cy, float scale, float rotate, int center_x, int center_y);
void doGestureChange(int cx, int cy, float scale, float rotate, int center_x, int center_y, bool isGestureEnd=false);
void doGestureEnd(int cx, int cy, float scale, float rotate, int center_x, int center_y);
void sendGestureStart(int cx, int cy, float scale, float rotate, int center_x, int center_y);
void sendGestureChange(int cx, int cy, float scale, float rotate, int center_x, int center_y);
void sendGestureEnd(int cx, int cy, float scale, float rotate, int center_x, int center_y);
void sendSingleTap(int cx, int cy, int modifiers);
// touch handling
bool doTouchEvent(int32_t type, NpPalmTouchEvent *event);
static BrowserAdapter* GetAndInitAdapter( AdapterBase* adapter );
static bool isSafeDir(const char* pszFileName);
bool prvSmartZoom(const Point& pt);
void invalidate(void);
void handlePaintInFrozenState(NpPalmDrawEvent* event);
void scale(double zoom);
void scaleAndScrollTo(double zoom, int x, int y);
void fireScrolledToEvent(int x, int y);
bool isActivated();
void setPageIdentifier(int32_t identifier);
void enableFastScaling(bool enable);
int showHighlight(QPainter* gc);
void removeHighlight();
void invalidateHighlightRectsRegion();
void updateMouseInFlashStatus(bool inFlashRect);
void updateFlashGestureLockStatus(bool gestureLockEnabled);
bool flashRectContainsPoint(const Point& pt);
bool rectContainsPoint(RectMap &rectMap, const Point& pt);
void updateMouseInInteractiveStatus(bool inInteractiveRect);
bool interactiveRectContainsPoint(const Point& pt);
void jsonToRects(const char* rectsArrayJson);
bool detectScrollableLayerUnderMouseDown(const Point& pagePt, const Point& mousePt);
bool scrollLayerUnderMouse(const Point& currentMousePtDoc);
void resetScrollableLayerScrollSession();
void showActiveScrollableLayer(QPainter* gc);
// used to create a scrim around a plugin rectangle "spotlight"
int showSpotlight(QPainter* gc);
void initSelectionReticleSurface();
void showSelectionReticle(QPainter* gc);
void invalidateSelectionReticleRegion();
bool sendRequestOffscreenChange(bool sync, int asyncDelayMillis);
bool isPointInList(const Point &point, const NpPalmTouchList &list);
bool shouldPassInputEvents();
bool shouldPassTouchEvents();
struct timeval m_lastPassedEventTime;
unsigned long long m_ft;
void scrollCaretIntoViewAfterResize(int oldwidth, int oldheight, double oldZoomLevel);
BrowserRect m_textCaretRect;
Point m_clickPt; ///< Point where mouse clicked (minus header)
Point m_penDownDoc; ///< Mouse down location in scaled document coordinates
bool m_dragging;
bool m_didDrag;
bool m_didHold;
bool m_sentToBS;
GSource *m_clickTimerSource;
static gboolean clickTimeoutCb(gpointer data);
void startClickTimer();
void stopClickTimer();
GSource *m_mouseHoldTimerSource;
static gboolean mouseHoldTimeoutCb(gpointer data);
void startMouseHoldTimer();
void stopMouseHoldTimer();
struct SentMouseHoldEvent {
SentMouseHoldEvent() : pt(0,0), sent(false) {}
void reset() {
sent = false;
}
void set(int cx, int cy)
{
pt.set(cx, cy);
sent = true;
}
Point pt;
bool sent;
};
SentMouseHoldEvent m_sentMouseHoldEvent;
GSource *m_zoomTimerSource;
static gboolean zoomTimerTimeoutCb(gpointer data);
bool animateZoom();
void startZoomAnimation(double zoom, int x, int y);
void stopZoomAnimation();
Point m_zoomPt;
double m_zoomTarget;
int m_zoomXInterval;
int m_zoomYInterval;
double m_zoomLevelInterval;
int m_headerHeight; ///< Height (in pixels) of the header which is a space above the page we don't draw.
void showScrollbar();
void startFadeScrollbar();
void stopFadeScrollbar();
static gboolean scrollbarFadeoutCb(gpointer data);
int mScrollbarOpacity;
GSource* mScrollbarFadeSource;
struct RecordedGestureEntry {
RecordedGestureEntry(float s, float r, int cX, int cY)
: scale(s)
, rotate(r)
, centerX(cX)
, centerY(cY) {
}
float scale;
float rotate;
int centerX;
int centerY;
};
std::list<RecordedGestureEntry> m_recordedGestures;
void recordGesture(float s, float r, int cX, int cY);
RecordedGestureEntry getAveragedGesture() const;
bool destroyBufferLock();
bool createBufferLock();
sem_t* m_bufferLock;
char* m_bufferLockName;
friend class BrowserAdapterData;
};
#endif /* BROWSERADAPTER_H */