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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
#include <stdint.h>
#include <set>
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/process/kill.h"
#include "base/strings/string16.h"
#include "base/supports_user_data.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/save_page_type.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/stop_find_action.h"
#include "ipc/ipc_sender.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
#if defined(OS_ANDROID)
#include "base/android/scoped_java_ref.h"
#endif
namespace base {
class DictionaryValue;
class TimeTicks;
}
namespace blink {
struct WebFindOptions;
}
namespace net {
struct LoadStateWithParam;
}
namespace content {
class BrowserContext;
class BrowserPluginGuestDelegate;
class InterstitialPage;
class PageState;
class RenderFrameHost;
class RenderProcessHost;
class RenderViewHost;
class RenderWidgetHostView;
class SiteInstance;
class WebContentsDelegate;
struct CustomContextMenuContext;
struct DropData;
struct Manifest;
struct PageImportanceSignals;
struct RendererPreferences;
// WebContents is the core class in content/. A WebContents renders web content
// (usually HTML) in a rectangular area.
//
// Instantiating one is simple:
// scoped_ptr<content::WebContents> web_contents(
// content::WebContents::Create(
// content::WebContents::CreateParams(browser_context)));
// gfx::NativeView view = web_contents->GetNativeView();
// // |view| is an HWND, NSView*, GtkWidget*, etc.; insert it into the view
// // hierarchy wherever it needs to go.
//
// That's it; go to your kitchen, grab a scone, and chill. WebContents will do
// all the multi-process stuff behind the scenes. More details are at
// http://www.chromium.org/developers/design-documents/multi-process-architecture .
//
// Each WebContents has exactly one NavigationController; each
// NavigationController belongs to one WebContents. The NavigationController can
// be obtained from GetController(), and is used to load URLs into the
// WebContents, navigate it backwards/forwards, etc. See navigation_controller.h
// for more details.
class WebContents : public PageNavigator,
public IPC::Sender,
public base::SupportsUserData {
public:
struct CONTENT_EXPORT CreateParams {
explicit CreateParams(BrowserContext* context);
CreateParams(const CreateParams& other);
~CreateParams();
CreateParams(BrowserContext* context, SiteInstance* site);
BrowserContext* browser_context;
// Specifying a SiteInstance here is optional. It can be set to avoid an
// extra process swap if the first navigation is expected to require a
// privileged process.
SiteInstance* site_instance;
// The process id of the frame initiating the open.
int opener_render_process_id;
// The routing id of the frame initiating the open.
int opener_render_frame_id;
// If the opener is suppressed, then the new WebContents doesn't hold a
// reference to its opener.
bool opener_suppressed;
// Indicates whether this WebContents was created with a window.opener.
// This is used when determining whether the WebContents is allowed to be
// closed via window.close(). This may be true even with a null |opener|
// (e.g., for blocked popups).
bool created_with_opener;
// The routing ids of the RenderView, main RenderFrame, and the widget for
// the main RenderFrame. Either all routing IDs must be provided or all must
// be MSG_ROUTING_NONE to have WebContents make the assignment. If provided,
// these routing IDs are associated with |site_instance->GetProcess()|.
int32_t routing_id;
int32_t main_frame_routing_id;
int32_t main_frame_widget_routing_id;
// The name of the top-level frame of the new window. It is non-empty
// when creating a named window (e.g. <a target="foo"> or
// window.open('', 'bar')).
std::string main_frame_name;
// Initial size of the new WebContent's view. Can be (0, 0) if not needed.
gfx::Size initial_size;
// True if the contents should be initially hidden.
bool initially_hidden;
// If non-null then this WebContents will be hosted by a BrowserPlugin.
BrowserPluginGuestDelegate* guest_delegate;
// Used to specify the location context which display the new view should
// belong. This can be nullptr if not needed.
gfx::NativeView context;
// Used to specify that the new WebContents creation is driven by the
// renderer process. In this case, the renderer-side objects, such as
// RenderFrame, have already been created on the renderer side, and
// WebContents construction should take this into account.
bool renderer_initiated_creation;
};
// Creates a new WebContents.
CONTENT_EXPORT static WebContents* Create(const CreateParams& params);
// Similar to Create() above but should be used when you need to prepopulate
// the SessionStorageNamespaceMap of the WebContents. This can happen if
// you duplicate a WebContents, try to reconstitute it from a saved state,
// or when you create a new WebContents based on another one (eg., when
// servicing a window.open() call).
//
// You do not want to call this. If you think you do, make sure you completely
// understand when SessionStorageNamespace objects should be cloned, why
// they should not be shared by multiple WebContents, and what bad things
// can happen if you share the object.
CONTENT_EXPORT static WebContents* CreateWithSessionStorage(
const CreateParams& params,
const SessionStorageNamespaceMap& session_storage_namespace_map);
// Returns the WebContents that owns the RenderViewHost, or nullptr if the
// render view host's delegate isn't a WebContents.
CONTENT_EXPORT static WebContents* FromRenderViewHost(RenderViewHost* rvh);
CONTENT_EXPORT static WebContents* FromRenderFrameHost(RenderFrameHost* rfh);
~WebContents() override {}
// Intrinsic tab state -------------------------------------------------------
// Gets/Sets the delegate.
virtual WebContentsDelegate* GetDelegate() = 0;
virtual void SetDelegate(WebContentsDelegate* delegate) = 0;
// Gets the controller for this WebContents.
virtual NavigationController& GetController() = 0;
virtual const NavigationController& GetController() const = 0;
// Returns the user browser context associated with this WebContents (via the
// NavigationController).
virtual content::BrowserContext* GetBrowserContext() const = 0;
// Gets the URL that is currently being displayed, if there is one.
// This method is deprecated. DO NOT USE! Pick either |GetVisibleURL| or
// |GetLastCommittedURL| as appropriate.
virtual const GURL& GetURL() const = 0;
// Gets the URL currently being displayed in the URL bar, if there is one.
// This URL might be a pending navigation that hasn't committed yet, so it is
// not guaranteed to match the current page in this WebContents. A typical
// example of this is interstitials, which show the URL of the new/loading
// page (active) but the security context is of the old page (last committed).
virtual const GURL& GetVisibleURL() const = 0;
// Gets the last committed URL. It represents the current page that is
// displayed in this WebContents. It represents the current security
// context.
virtual const GURL& GetLastCommittedURL() const = 0;
// Return the currently active RenderProcessHost and RenderViewHost. Each of
// these may change over time.
virtual RenderProcessHost* GetRenderProcessHost() const = 0;
// Returns the main frame for the currently active view.
virtual RenderFrameHost* GetMainFrame() = 0;
// Returns the focused frame for the currently active view.
virtual RenderFrameHost* GetFocusedFrame() = 0;
// Returns the current RenderFrameHost for a given FrameTreeNode ID if it is
// part of this tab. See RenderFrameHost::GetFrameTreeNodeId for documentation
// on this ID.
virtual RenderFrameHost* FindFrameByFrameTreeNodeId(
int frame_tree_node_id) = 0;
// Calls |on_frame| for each frame in the currently active view.
// Note: The RenderFrameHost parameter is not guaranteed to have a live
// RenderFrame counterpart in the renderer process. Callbacks should check
// IsRenderFrameLive, as sending IPC messages to it in this case will fail
// silently.
virtual void ForEachFrame(
const base::Callback<void(RenderFrameHost*)>& on_frame) = 0;
// Returns a vector of all RenderFrameHosts in the currently active view in
// breadth-first traversal order.
virtual std::vector<RenderFrameHost*> GetAllFrames() = 0;
// Sends the given IPC to all live frames in this WebContents and returns the
// number of sent messages (i.e. the number of processed frames).
virtual int SendToAllFrames(IPC::Message* message) = 0;
// Gets the current RenderViewHost for this tab.
virtual RenderViewHost* GetRenderViewHost() const = 0;
// Gets the current RenderViewHost's routing id. Returns
// MSG_ROUTING_NONE when there is no RenderViewHost.
virtual int GetRoutingID() const = 0;
// Returns the currently active RenderWidgetHostView. This may change over
// time and can be nullptr (during setup and teardown).
virtual RenderWidgetHostView* GetRenderWidgetHostView() const = 0;
// Causes the current page to be closed, including running its onunload event
// handler.
virtual void ClosePage() = 0;
// Returns the currently active fullscreen widget. If there is none, returns
// nullptr.
virtual RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const = 0;
// Returns the theme color for the underlying content as set by the
// theme-color meta tag.
virtual SkColor GetThemeColor() const = 0;
// Create a WebUI page for the given url. In most cases, this doesn't need to
// be called by embedders since content will create its own WebUI objects as
// necessary. However if the embedder wants to create its own WebUI object and
// keep track of it manually, it can use this. |frame_name| is used to
// identify the frame and cannot be empty.
virtual WebUI* CreateSubframeWebUI(const GURL& url,
const std::string& frame_name) = 0;
// Returns the committed WebUI if one exists, otherwise the pending one.
virtual WebUI* GetWebUI() const = 0;
virtual WebUI* GetCommittedWebUI() const = 0;
// Allows overriding the user agent used for NavigationEntries it owns.
virtual void SetUserAgentOverride(const std::string& override) = 0;
virtual const std::string& GetUserAgentOverride() const = 0;
// Enable the accessibility tree for this WebContents in the renderer,
// but don't enable creating a native accessibility tree on the browser
// side.
virtual void EnableTreeOnlyAccessibilityMode() = 0;
// Returns true only if "tree only" accessibility mode is on.
virtual bool IsTreeOnlyAccessibilityModeForTesting() const = 0;
// Returns true only if complete accessibility mode is on, meaning there's
// both renderer accessibility, and a native browser accessibility tree.
virtual bool IsFullAccessibilityModeForTesting() const = 0;
#if defined(OS_WIN)
virtual void SetParentNativeViewAccessible(
gfx::NativeViewAccessible accessible_parent) = 0;
#endif
virtual const PageImportanceSignals& GetPageImportanceSignals() const = 0;
// Tab navigation state ------------------------------------------------------
// Returns the current navigation properties, which if a navigation is
// pending may be provisional (e.g., the navigation could result in a
// download, in which case the URL would revert to what it was previously).
virtual const base::string16& GetTitle() const = 0;
// The max page ID for any page that the current SiteInstance has loaded in
// this WebContents. Page IDs are specific to a given SiteInstance and
// WebContents, corresponding to a specific RenderView in the renderer.
// Page IDs increase with each new page that is loaded by a tab.
virtual int32_t GetMaxPageID() = 0;
// The max page ID for any page that the given SiteInstance has loaded in
// this WebContents.
virtual int32_t GetMaxPageIDForSiteInstance(SiteInstance* site_instance) = 0;
// Returns the SiteInstance associated with the current page.
virtual SiteInstance* GetSiteInstance() const = 0;
// Returns the SiteInstance for the pending navigation, if any. Otherwise
// returns the current SiteInstance.
virtual SiteInstance* GetPendingSiteInstance() const = 0;
// Returns whether this WebContents is loading a resource.
virtual bool IsLoading() const = 0;
// Returns whether this WebContents is loading and and the load is to a
// different top-level document (rather than being a navigation within the
// same document). This being true implies that IsLoading() is also true.
virtual bool IsLoadingToDifferentDocument() const = 0;
// Returns whether this WebContents is waiting for a first-response for the
// main resource of the page.
virtual bool IsWaitingForResponse() const = 0;
// Returns the current load state and the URL associated with it.
// The load state is only updated while IsLoading() is true.
virtual const net::LoadStateWithParam& GetLoadState() const = 0;
virtual const base::string16& GetLoadStateHost() const = 0;
// Returns the upload progress.
virtual uint64_t GetUploadSize() const = 0;
virtual uint64_t GetUploadPosition() const = 0;
// Returns the character encoding of the page.
virtual const std::string& GetEncoding() const = 0;
// True if this is a secure page which displayed insecure content.
virtual bool DisplayedInsecureContent() const = 0;
// Internal state ------------------------------------------------------------
// Indicates whether the WebContents is being captured (e.g., for screenshots
// or mirroring). Increment calls must be balanced with an equivalent number
// of decrement calls. |capture_size| specifies the capturer's video
// resolution, but can be empty to mean "unspecified." The first screen
// capturer that provides a non-empty |capture_size| will override the value
// returned by GetPreferredSize() until all captures have ended.
virtual void IncrementCapturerCount(const gfx::Size& capture_size) = 0;
virtual void DecrementCapturerCount() = 0;
virtual int GetCapturerCount() const = 0;
// Indicates/Sets whether all audio output from this WebContents is muted.
virtual bool IsAudioMuted() const = 0;
virtual void SetAudioMuted(bool mute) = 0;
// Indicates whether this tab should be considered crashed. The setter will
// also notify the delegate when the flag is changed.
virtual bool IsCrashed() const = 0;
virtual void SetIsCrashed(base::TerminationStatus status, int error_code) = 0;
virtual base::TerminationStatus GetCrashedStatus() const = 0;
virtual int GetCrashedErrorCode() const = 0;
// Whether the tab is in the process of being destroyed.
virtual bool IsBeingDestroyed() const = 0;
// Convenience method for notifying the delegate of a navigation state
// change.
virtual void NotifyNavigationStateChanged(InvalidateTypes changed_flags) = 0;
// Get/Set the last time that the WebContents was made active (either when it
// was created or shown with WasShown()).
virtual base::TimeTicks GetLastActiveTime() const = 0;
virtual void SetLastActiveTime(base::TimeTicks last_active_time) = 0;
// Invoked when the WebContents becomes shown/hidden.
virtual void WasShown() = 0;
virtual void WasHidden() = 0;
// Returns true if the before unload and unload listeners need to be
// fired. The value of this changes over time. For example, if true and the
// before unload listener is executed and allows the user to exit, then this
// returns false.
virtual bool NeedToFireBeforeUnload() = 0;
// Runs the beforeunload handler for the main frame. See also ClosePage and
// SwapOut in RenderViewHost, which run the unload handler.
//
// |for_cross_site_transition| indicates whether this call is for the current
// frame during a cross-process navigation. False means we're closing the
// entire tab.
//
// TODO(creis): We should run the beforeunload handler for every frame that
// has one.
virtual void DispatchBeforeUnload(bool for_cross_site_transition) = 0;
// Attaches this inner WebContents to its container frame
// |outer_contents_frame| in |outer_web_contents|.
virtual void AttachToOuterWebContentsFrame(
WebContents* outer_web_contents,
RenderFrameHost* outer_contents_frame) = 0;
// Commands ------------------------------------------------------------------
// Stop any pending navigation.
virtual void Stop() = 0;
// Creates a new WebContents with the same state as this one. The returned
// heap-allocated pointer is owned by the caller.
virtual WebContents* Clone() = 0;
// Reloads the focused frame.
virtual void ReloadFocusedFrame(bool ignore_cache) = 0;
// Reloads all the Lo-Fi images in this WebContents. Ignores the cache and
// reloads from the network.
virtual void ReloadLoFiImages() = 0;
// Editing commands ----------------------------------------------------------
virtual void Undo() = 0;
virtual void Redo() = 0;
virtual void Cut() = 0;
virtual void Copy() = 0;
virtual void CopyToFindPboard() = 0;
virtual void Paste() = 0;
virtual void PasteAndMatchStyle() = 0;
virtual void Delete() = 0;
virtual void SelectAll() = 0;
virtual void Unselect() = 0;
// Adjust the selection starting and ending points in the focused frame by
// the given amounts. A negative amount moves the selection towards the
// beginning of the document, a positive amount moves the selection towards
// the end of the document.
virtual void AdjustSelectionByCharacterOffset(int start_adjust,
int end_adjust) = 0;
// Replaces the currently selected word or a word around the cursor.
virtual void Replace(const base::string16& word) = 0;
// Replaces the misspelling in the current selection.
virtual void ReplaceMisspelling(const base::string16& word) = 0;
// Let the renderer know that the menu has been closed.
virtual void NotifyContextMenuClosed(
const CustomContextMenuContext& context) = 0;
// Executes custom context menu action that was provided from Blink.
virtual void ExecuteCustomContextMenuCommand(
int action, const CustomContextMenuContext& context) = 0;
// Views and focus -----------------------------------------------------------
// Returns the native widget that contains the contents of the tab.
virtual gfx::NativeView GetNativeView() = 0;
// Returns the native widget with the main content of the tab (i.e. the main
// render view host, though there may be many popups in the tab as children of
// the container).
virtual gfx::NativeView GetContentNativeView() = 0;
// Returns the outermost native view. This will be used as the parent for
// dialog boxes.
virtual gfx::NativeWindow GetTopLevelNativeWindow() = 0;
// Computes the rectangle for the native widget that contains the contents of
// the tab in the screen coordinate system.
virtual gfx::Rect GetContainerBounds() = 0;
// Get the bounds of the View, relative to the parent.
virtual gfx::Rect GetViewBounds() = 0;
// Returns the current drop data, if any.
virtual DropData* GetDropData() = 0;
// Sets focus to the native widget for this tab.
virtual void Focus() = 0;
// Sets focus to the appropriate element when the WebContents is shown the
// first time.
virtual void SetInitialFocus() = 0;
// Stores the currently focused view.
virtual void StoreFocus() = 0;
// Restores focus to the last focus view. If StoreFocus has not yet been
// invoked, SetInitialFocus is invoked.
virtual void RestoreFocus() = 0;
// Focuses the first (last if |reverse| is true) element in the page.
// Invoked when this tab is getting the focus through tab traversal (|reverse|
// is true when using Shift-Tab).
virtual void FocusThroughTabTraversal(bool reverse) = 0;
// Interstitials -------------------------------------------------------------
// Various other systems need to know about our interstitials.
virtual bool ShowingInterstitialPage() const = 0;
// Returns the currently showing interstitial, nullptr if no interstitial is
// showing.
virtual InterstitialPage* GetInterstitialPage() const = 0;
// Misc state & callbacks ----------------------------------------------------
// Check whether we can do the saving page operation this page given its MIME
// type.
virtual bool IsSavable() = 0;
// Prepare for saving the current web page to disk.
virtual void OnSavePage() = 0;
// Save page with the main HTML file path, the directory for saving resources,
// and the save type: HTML only or complete web page. Returns true if the
// saving process has been initiated successfully.
virtual bool SavePage(const base::FilePath& main_file,
const base::FilePath& dir_path,
SavePageType save_type) = 0;
// Saves the given frame's URL to the local filesystem.
virtual void SaveFrame(const GURL& url,
const Referrer& referrer) = 0;
// Saves the given frame's URL to the local filesystem. The headers, if
// provided, is used to make a request to the URL rather than using cache.
// Format of |headers| is a new line separated list of key value pairs:
// "<key1>: <value1>\n<key2>: <value2>".
virtual void SaveFrameWithHeaders(const GURL& url,
const Referrer& referrer,
const std::string& headers) = 0;
// Generate an MHTML representation of the current page in the given file.
virtual void GenerateMHTML(
const base::FilePath& file,
const base::Callback<void(int64_t /* size of the file */)>& callback) = 0;
// Returns the contents MIME type after a navigation.
virtual const std::string& GetContentsMimeType() const = 0;
// Returns true if this WebContents will notify about disconnection.
virtual bool WillNotifyDisconnection() const = 0;
// Override the encoding and reload the page by sending down
// ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda
// the opposite of this, by which 'browser' is notified of
// the encoding of the current tab from 'renderer' (determined by
// auto-detect, http header, meta, bom detection, etc).
virtual void SetOverrideEncoding(const std::string& encoding) = 0;
// Remove any user-defined override encoding and reload by sending down
// ViewMsg_ResetPageEncodingToDefault to the renderer.
virtual void ResetOverrideEncoding() = 0;
// Returns the settings which get passed to the renderer.
virtual content::RendererPreferences* GetMutableRendererPrefs() = 0;
// Tells the tab to close now. The tab will take care not to close until it's
// out of nested message loops.
virtual void Close() = 0;
// A render view-originated drag has ended. Informs the render view host and
// WebContentsDelegate.
virtual void SystemDragEnded() = 0;
// Notification the user has made a gesture while focus was on the
// page. This is used to avoid uninitiated user downloads (aka carpet
// bombing), see DownloadRequestLimiter for details.
virtual void UserGestureDone() = 0;
// Indicates if this tab was explicitly closed by the user (control-w, close
// tab menu item...). This is false for actions that indirectly close the tab,
// such as closing the window. The setter is maintained by TabStripModel, and
// the getter only useful from within TAB_CLOSED notification
virtual void SetClosedByUserGesture(bool value) = 0;
virtual bool GetClosedByUserGesture() const = 0;
// Opens view-source tab for this contents.
virtual void ViewSource() = 0;
virtual void ViewFrameSource(const GURL& url,
const PageState& page_state) = 0;
// Gets the minimum/maximum zoom percent.
virtual int GetMinimumZoomPercent() const = 0;
virtual int GetMaximumZoomPercent() const = 0;
// Set the renderer's page scale to the given factor.
virtual void SetPageScale(float page_scale_factor) = 0;
// Gets the preferred size of the contents.
virtual gfx::Size GetPreferredSize() const = 0;
// Called when the reponse to a pending mouse lock request has arrived.
// Returns true if |allowed| is true and the mouse has been successfully
// locked.
virtual bool GotResponseToLockMouseRequest(bool allowed) = 0;
// Called when the user has selected a color in the color chooser.
virtual void DidChooseColorInColorChooser(SkColor color) = 0;
// Called when the color chooser has ended.
virtual void DidEndColorChooser() = 0;
// Returns true if the location bar should be focused by default rather than
// the page contents. The view calls this function when the tab is focused
// to see what it should do.
virtual bool FocusLocationBarByDefault() = 0;
// Does this have an opener associated with it?
virtual bool HasOpener() const = 0;
// Returns the opener if HasOpener() is true, or nullptr otherwise.
virtual WebContents* GetOpener() const = 0;
typedef base::Callback<void(
int, /* id */
int, /* HTTP status code */
const GURL&, /* image_url */
const std::vector<SkBitmap>&, /* bitmaps */
/* The sizes in pixel of the bitmaps before they were resized due to the
max bitmap size passed to DownloadImage(). Each entry in the bitmaps
vector corresponds to an entry in the sizes vector. If a bitmap was
resized, there should be a single returned bitmap. */
const std::vector<gfx::Size>&)>
ImageDownloadCallback;
// Sends a request to download the given image |url| and returns the unique
// id of the download request. When the download is finished, |callback| will
// be called with the bitmaps received from the renderer.
// If |is_favicon| is true, the cookies are not sent and not accepted during
// download.
// Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out
// from the bitmap results. If there are no bitmap results <=
// |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and
// is the only result. A |max_bitmap_size| of 0 means unlimited.
// If |bypass_cache| is true, |url| is requested from the server even if it
// is present in the browser cache.
virtual int DownloadImage(const GURL& url,
bool is_favicon,
uint32_t max_bitmap_size,
bool bypass_cache,
const ImageDownloadCallback& callback) = 0;
// Returns true if the WebContents is responsible for displaying a subframe
// in a different process from its parent page.
// TODO: this doesn't really belong here. With site isolation, this should be
// removed since we can then embed iframes in different processes.
virtual bool IsSubframe() const = 0;
// Finds text on a page. |search_text| should not be empty.
virtual void Find(int request_id,
const base::string16& search_text,
const blink::WebFindOptions& options) = 0;
// Notifies the renderer that the user has closed the FindInPage window
// (and what action to take regarding the selection).
virtual void StopFinding(StopFindAction action) = 0;
// Requests the renderer to insert CSS into the main frame's document.
virtual void InsertCSS(const std::string& css) = 0;
// Returns true if audio has recently been audible from the WebContents.
virtual bool WasRecentlyAudible() = 0;
typedef base::Callback<void(const Manifest&)> GetManifestCallback;
// Requests the Manifest of the main frame's document.
virtual void GetManifest(const GetManifestCallback& callback) = 0;
typedef base::Callback<void(bool)> HasManifestCallback;
// Returns true if the main frame has a <link> to a web manifest, otherwise
// false. This method does not guarantee that the manifest exists at the
// specified location or is valid.
virtual void HasManifest(const HasManifestCallback& callback) = 0;
// Requests the renderer to exit fullscreen.
// |will_cause_resize| indicates whether the fullscreen change causes a
// view resize. e.g. This will be false when going from tab fullscreen to
// browser fullscreen.
virtual void ExitFullscreen(bool will_cause_resize) = 0;
// Unblocks requests from renderer for a newly created window. This is
// used in showCreatedWindow() or sometimes later in cases where
// delegate->ShouldResumeRequestsForCreatedWindow() indicated the requests
// should not yet be resumed. Then the client is responsible for calling this
// as soon as they are ready.
virtual void ResumeLoadingCreatedWebContents() = 0;
// Requests to resume the current media session.
virtual void ResumeMediaSession() = 0;
// Requests to suspend the current media session.
virtual void SuspendMediaSession() = 0;
// Requests to stop the current media session.
virtual void StopMediaSession() = 0;
#if defined(OS_ANDROID)
CONTENT_EXPORT static WebContents* FromJavaWebContents(
jobject jweb_contents_android);
virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() = 0;
#elif defined(OS_MACOSX)
// Allowing other views disables optimizations which assume that only a single
// WebContents is present.
virtual void SetAllowOtherViews(bool allow) = 0;
// Returns true if other views are allowed, false otherwise.
virtual bool GetAllowOtherViews() = 0;
#endif // OS_ANDROID
private:
// This interface should only be implemented inside content.
friend class WebContentsImpl;
WebContents() {}
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
|