Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.h

Issue 481003002: Introduce WebViewGuestDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2_extensions_render_frame_observer
Patch Set: Small changes are made. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_
6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" 11 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h"
12 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" 12 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h"
13 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" 13 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
14 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" 14 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
15 #include "chrome/common/extensions/api/web_view_internal.h" 15 #include "chrome/common/extensions/api/web_view_internal.h"
16 #include "content/public/browser/javascript_dialog_manager.h" 16 #include "content/public/browser/javascript_dialog_manager.h"
17 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
19 #include "extensions/browser/guest_view/guest_view.h" 19 #include "extensions/browser/guest_view/guest_view.h"
20 #include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h"
20 #include "extensions/browser/script_executor.h" 21 #include "extensions/browser/script_executor.h"
21 #include "third_party/WebKit/public/web/WebFindOptions.h" 22 #include "third_party/WebKit/public/web/WebFindOptions.h"
22 23
23 #if defined(OS_CHROMEOS)
24 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
25 #endif
26
27 class RenderViewContextMenu;
28
29 namespace ui {
30 class SimpleMenuModel;
31 } // namespace ui
32
33 namespace extensions { 24 namespace extensions {
34 25
35 namespace webview_api = api::web_view_internal;
36
37 class WebViewInternalFindFunction; 26 class WebViewInternalFindFunction;
38 27
39 // A WebViewGuest provides the browser-side implementation of the <webview> API 28 // A WebViewGuest provides the browser-side implementation of the <webview> API
40 // and manages the dispatch of <webview> extension events. WebViewGuest is 29 // and manages the dispatch of <webview> extension events. WebViewGuest is
41 // created on attachment. That is, when a guest WebContents is associated with 30 // created on attachment. That is, when a guest WebContents is associated with
42 // a particular embedder WebContents. This happens on either initial navigation 31 // a particular embedder WebContents. This happens on either initial navigation
43 // or through the use of the New Window API, when a new window is attached to 32 // or through the use of the New Window API, when a new window is attached to
44 // a particular <webview>. 33 // a particular <webview>.
45 class WebViewGuest : public GuestView<WebViewGuest>, 34 class WebViewGuest : public GuestView<WebViewGuest>,
46 public content::NotificationObserver { 35 public content::NotificationObserver {
(...skipping 15 matching lines...) Expand all
62 51
63 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a 52 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a
64 // WebViewGuest. 53 // WebViewGuest.
65 static int GetViewInstanceId(content::WebContents* contents); 54 static int GetViewInstanceId(content::WebContents* contents);
66 55
67 static const char Type[]; 56 static const char Type[];
68 57
69 // Request navigating the guest to the provided |src| URL. 58 // Request navigating the guest to the provided |src| URL.
70 void NavigateGuest(const std::string& src); 59 void NavigateGuest(const std::string& src);
71 60
72 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector;
73 // Shows the context menu for the guest. 61 // Shows the context menu for the guest.
74 // |items| acts as a filter. This restricts the current context's default 62 // |items| acts as a filter. This restricts the current context's default
75 // menu items to contain only the items from |items|. 63 // menu items to contain only the items from |items|.
76 // |items| == NULL means no filtering will be applied. 64 // |items| == NULL means no filtering will be applied.
77 void ShowContextMenu(int request_id, const MenuItemVector* items); 65 void ShowContextMenu(
66 int request_id,
67 const WebViewGuestDelegate::MenuItemVector* items);
78 68
79 // Sets the frame name of the guest. 69 // Sets the frame name of the guest.
80 void SetName(const std::string& name); 70 void SetName(const std::string& name);
81 71
82 // Set the zoom factor. 72 // Set the zoom factor.
83 void SetZoom(double zoom_factor); 73 void SetZoom(double zoom_factor);
84 74
85 // GuestViewBase implementation. 75 // GuestViewBase implementation.
86 virtual const char* GetAPINamespace() OVERRIDE; 76 virtual const char* GetAPINamespace() OVERRIDE;
87 virtual void CreateWebContents( 77 virtual void CreateWebContents(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 226
237 ScriptExecutor* script_executor() { return script_executor_.get(); } 227 ScriptExecutor* script_executor() { return script_executor_.get(); }
238 228
239 private: 229 private:
240 friend class WebViewPermissionHelper; 230 friend class WebViewPermissionHelper;
241 WebViewGuest(content::BrowserContext* browser_context, 231 WebViewGuest(content::BrowserContext* browser_context,
242 int guest_instance_id); 232 int guest_instance_id);
243 233
244 virtual ~WebViewGuest(); 234 virtual ~WebViewGuest();
245 235
246 // Returns the top level items (ignoring submenus) as Value.
247 static scoped_ptr<base::ListValue> MenuModelToValue(
248 const ui::SimpleMenuModel& menu_model);
249
250 void AttachWebViewHelpers(content::WebContents* contents); 236 void AttachWebViewHelpers(content::WebContents* contents);
251 237
252 void OnWebViewNewWindowResponse(int new_window_instance_id, 238 void OnWebViewNewWindowResponse(int new_window_instance_id,
253 bool allow, 239 bool allow,
254 const std::string& user_input); 240 const std::string& user_input);
255 241
256 // WebContentsObserver implementation. 242 // WebContentsObserver implementation.
257 virtual void DidCommitProvisionalLoadForFrame( 243 virtual void DidCommitProvisionalLoadForFrame(
258 content::RenderFrameHost* render_frame_host, 244 content::RenderFrameHost* render_frame_host,
259 const GURL& url, 245 const GURL& url,
(...skipping 24 matching lines...) Expand all
284 270
285 // Called when a redirect notification occurs. 271 // Called when a redirect notification occurs.
286 void LoadRedirect(const GURL& old_url, 272 void LoadRedirect(const GURL& old_url,
287 const GURL& new_url, 273 const GURL& new_url,
288 bool is_top_level); 274 bool is_top_level);
289 275
290 void PushWebViewStateToIOThread(); 276 void PushWebViewStateToIOThread();
291 static void RemoveWebViewStateFromIOThread( 277 static void RemoveWebViewStateFromIOThread(
292 content::WebContents* web_contents); 278 content::WebContents* web_contents);
293 279
294 #if defined(OS_CHROMEOS)
295 // Notification of a change in the state of an accessibility setting.
296 void OnAccessibilityStatusChanged(
297 const chromeos::AccessibilityStatusEventDetails& details);
298 #endif
299
300 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host);
301
302 void LoadURLWithParams(const GURL& url, 280 void LoadURLWithParams(const GURL& url,
303 const content::Referrer& referrer, 281 const content::Referrer& referrer,
304 content::PageTransition transition_type, 282 content::PageTransition transition_type,
305 content::WebContents* web_contents); 283 content::WebContents* web_contents);
306 284
307 void RequestNewWindowPermission( 285 void RequestNewWindowPermission(
308 WindowOpenDisposition disposition, 286 WindowOpenDisposition disposition,
309 const gfx::Rect& initial_bounds, 287 const gfx::Rect& initial_bounds,
310 bool user_gesture, 288 bool user_gesture,
311 content::WebContents* new_contents); 289 content::WebContents* new_contents);
(...skipping 21 matching lines...) Expand all
333 311
334 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); 312 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event);
335 313
336 void SetUpAutoSize(); 314 void SetUpAutoSize();
337 315
338 ObserverList<ScriptExecutionObserver> script_observers_; 316 ObserverList<ScriptExecutionObserver> script_observers_;
339 scoped_ptr<ScriptExecutor> script_executor_; 317 scoped_ptr<ScriptExecutor> script_executor_;
340 318
341 content::NotificationRegistrar notification_registrar_; 319 content::NotificationRegistrar notification_registrar_;
342 320
343 // A counter to generate a unique request id for a context menu request.
344 // We only need the ids to be unique for a given WebViewGuest.
345 int pending_context_menu_request_id_;
346
347 // True if the user agent is overridden. 321 // True if the user agent is overridden.
348 bool is_overriding_user_agent_; 322 bool is_overriding_user_agent_;
349 323
350 // Set to |true| if ChromeVox was already injected in main frame.
351 bool chromevox_injected_;
352
353 // Stores the current zoom factor.
354 double current_zoom_factor_;
355
356 // Stores the window name of the main frame of the guest. 324 // Stores the window name of the main frame of the guest.
357 std::string name_; 325 std::string name_;
358 326
359 // Handles find requests and replies for the webview find API. 327 // Handles find requests and replies for the webview find API.
360 WebViewFindHelper find_helper_; 328 WebViewFindHelper find_helper_;
361 329
362 // Handles the JavaScript dialog requests. 330 // Handles the JavaScript dialog requests.
363 JavaScriptDialogHelper javascript_dialog_helper_; 331 JavaScriptDialogHelper javascript_dialog_helper_;
364 332
365 // Handels permission requests. 333 // Handels permission requests.
366 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; 334 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_;
367 335
336 scoped_ptr<WebViewGuestDelegate> web_view_guest_delegate_;
337
368 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, 338 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled,
369 bool final_update); 339 bool final_update);
370 340
371 // Holds the RenderViewContextMenu that has been built but yet to be
372 // shown. This is .Reset() after ShowContextMenu().
373 scoped_ptr<RenderViewContextMenu> pending_menu_;
374
375 #if defined(OS_CHROMEOS)
376 // Subscription to receive notifications on changes to a11y settings.
377 scoped_ptr<chromeos::AccessibilityStatusSubscription>
378 accessibility_subscription_;
379 #endif
380
381 // Tracks the name, and target URL of the new window. Once the first 341 // Tracks the name, and target URL of the new window. Once the first
382 // navigation commits, we no longer track this information. 342 // navigation commits, we no longer track this information.
383 struct NewWindowInfo { 343 struct NewWindowInfo {
384 GURL url; 344 GURL url;
385 std::string name; 345 std::string name;
386 bool changed; 346 bool changed;
387 NewWindowInfo(const GURL& url, const std::string& name) : 347 NewWindowInfo(const GURL& url, const std::string& name) :
388 url(url), 348 url(url),
389 name(name), 349 name(name),
390 changed(false) {} 350 changed(false) {}
391 }; 351 };
392 352
393 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; 353 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap;
394 PendingWindowMap pending_new_windows_; 354 PendingWindowMap pending_new_windows_;
395 355
396 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); 356 DISALLOW_COPY_AND_ASSIGN(WebViewGuest);
397 }; 357 };
398 358
399 } // namespace extensions 359 } // namespace extensions
400 360
401 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ 361 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698