| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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); | 280 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); |
| 301 | 281 |
| 302 void LoadURLWithParams(const GURL& url, | 282 void LoadURLWithParams(const GURL& url, |
| 303 const content::Referrer& referrer, | 283 const content::Referrer& referrer, |
| 304 content::PageTransition transition_type, | 284 content::PageTransition transition_type, |
| 305 content::WebContents* web_contents); | 285 content::WebContents* web_contents); |
| 306 | 286 |
| 307 void RequestNewWindowPermission( | 287 void RequestNewWindowPermission( |
| 308 WindowOpenDisposition disposition, | 288 WindowOpenDisposition disposition, |
| 309 const gfx::Rect& initial_bounds, | 289 const gfx::Rect& initial_bounds, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 333 | 313 |
| 334 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); | 314 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); |
| 335 | 315 |
| 336 void SetUpAutoSize(); | 316 void SetUpAutoSize(); |
| 337 | 317 |
| 338 ObserverList<ScriptExecutionObserver> script_observers_; | 318 ObserverList<ScriptExecutionObserver> script_observers_; |
| 339 scoped_ptr<ScriptExecutor> script_executor_; | 319 scoped_ptr<ScriptExecutor> script_executor_; |
| 340 | 320 |
| 341 content::NotificationRegistrar notification_registrar_; | 321 content::NotificationRegistrar notification_registrar_; |
| 342 | 322 |
| 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. | 323 // True if the user agent is overridden. |
| 348 bool is_overriding_user_agent_; | 324 bool is_overriding_user_agent_; |
| 349 | 325 |
| 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. | 326 // Stores the window name of the main frame of the guest. |
| 357 std::string name_; | 327 std::string name_; |
| 358 | 328 |
| 359 // Handles find requests and replies for the webview find API. | 329 // Handles find requests and replies for the webview find API. |
| 360 WebViewFindHelper find_helper_; | 330 WebViewFindHelper find_helper_; |
| 361 | 331 |
| 362 // Handles the JavaScript dialog requests. | 332 // Handles the JavaScript dialog requests. |
| 363 JavaScriptDialogHelper javascript_dialog_helper_; | 333 JavaScriptDialogHelper javascript_dialog_helper_; |
| 364 | 334 |
| 365 // Handels permission requests. | 335 // Handels permission requests. |
| 366 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; | 336 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; |
| 367 | 337 |
| 338 scoped_ptr<WebViewGuestDelegate> web_view_guest_delegate_; |
| 339 |
| 368 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, | 340 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, |
| 369 bool final_update); | 341 bool final_update); |
| 370 | 342 |
| 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 | 343 // Tracks the name, and target URL of the new window. Once the first |
| 382 // navigation commits, we no longer track this information. | 344 // navigation commits, we no longer track this information. |
| 383 struct NewWindowInfo { | 345 struct NewWindowInfo { |
| 384 GURL url; | 346 GURL url; |
| 385 std::string name; | 347 std::string name; |
| 386 bool changed; | 348 bool changed; |
| 387 NewWindowInfo(const GURL& url, const std::string& name) : | 349 NewWindowInfo(const GURL& url, const std::string& name) : |
| 388 url(url), | 350 url(url), |
| 389 name(name), | 351 name(name), |
| 390 changed(false) {} | 352 changed(false) {} |
| 391 }; | 353 }; |
| 392 | 354 |
| 393 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 355 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
| 394 PendingWindowMap pending_new_windows_; | 356 PendingWindowMap pending_new_windows_; |
| 395 | 357 |
| 396 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 358 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
| 397 }; | 359 }; |
| 398 | 360 |
| 399 } // namespace extensions | 361 } // namespace extensions |
| 400 | 362 |
| 401 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 363 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
| OLD | NEW |