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" | |
21 #include "extensions/browser/script_executor.h" | 20 #include "extensions/browser/script_executor.h" |
22 #include "third_party/WebKit/public/web/WebFindOptions.h" | 21 #include "third_party/WebKit/public/web/WebFindOptions.h" |
23 | 22 |
| 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 |
24 namespace extensions { | 33 namespace extensions { |
25 | 34 |
| 35 namespace webview_api = api::web_view_internal; |
| 36 |
26 class WebViewInternalFindFunction; | 37 class WebViewInternalFindFunction; |
27 | 38 |
28 // A WebViewGuest provides the browser-side implementation of the <webview> API | 39 // A WebViewGuest provides the browser-side implementation of the <webview> API |
29 // and manages the dispatch of <webview> extension events. WebViewGuest is | 40 // and manages the dispatch of <webview> extension events. WebViewGuest is |
30 // created on attachment. That is, when a guest WebContents is associated with | 41 // created on attachment. That is, when a guest WebContents is associated with |
31 // a particular embedder WebContents. This happens on either initial navigation | 42 // a particular embedder WebContents. This happens on either initial navigation |
32 // or through the use of the New Window API, when a new window is attached to | 43 // or through the use of the New Window API, when a new window is attached to |
33 // a particular <webview>. | 44 // a particular <webview>. |
34 class WebViewGuest : public GuestView<WebViewGuest>, | 45 class WebViewGuest : public GuestView<WebViewGuest>, |
35 public content::NotificationObserver { | 46 public content::NotificationObserver { |
(...skipping 15 matching lines...) Expand all Loading... |
51 | 62 |
52 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a | 63 // Returns guestview::kInstanceIDNone if |contents| does not correspond to a |
53 // WebViewGuest. | 64 // WebViewGuest. |
54 static int GetViewInstanceId(content::WebContents* contents); | 65 static int GetViewInstanceId(content::WebContents* contents); |
55 | 66 |
56 static const char Type[]; | 67 static const char Type[]; |
57 | 68 |
58 // Request navigating the guest to the provided |src| URL. | 69 // Request navigating the guest to the provided |src| URL. |
59 void NavigateGuest(const std::string& src); | 70 void NavigateGuest(const std::string& src); |
60 | 71 |
| 72 typedef std::vector<linked_ptr<webview_api::ContextMenuItem> > MenuItemVector; |
61 // Shows the context menu for the guest. | 73 // Shows the context menu for the guest. |
62 // |items| acts as a filter. This restricts the current context's default | 74 // |items| acts as a filter. This restricts the current context's default |
63 // menu items to contain only the items from |items|. | 75 // menu items to contain only the items from |items|. |
64 // |items| == NULL means no filtering will be applied. | 76 // |items| == NULL means no filtering will be applied. |
65 void ShowContextMenu( | 77 void ShowContextMenu(int request_id, const MenuItemVector* items); |
66 int request_id, | |
67 const WebViewGuestDelegate::MenuItemVector* items); | |
68 | 78 |
69 // Sets the frame name of the guest. | 79 // Sets the frame name of the guest. |
70 void SetName(const std::string& name); | 80 void SetName(const std::string& name); |
71 | 81 |
72 // Set the zoom factor. | 82 // Set the zoom factor. |
73 void SetZoom(double zoom_factor); | 83 void SetZoom(double zoom_factor); |
74 | 84 |
75 // GuestViewBase implementation. | 85 // GuestViewBase implementation. |
76 virtual const char* GetAPINamespace() OVERRIDE; | 86 virtual const char* GetAPINamespace() OVERRIDE; |
77 virtual void CreateWebContents( | 87 virtual void CreateWebContents( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 236 |
227 ScriptExecutor* script_executor() { return script_executor_.get(); } | 237 ScriptExecutor* script_executor() { return script_executor_.get(); } |
228 | 238 |
229 private: | 239 private: |
230 friend class WebViewPermissionHelper; | 240 friend class WebViewPermissionHelper; |
231 WebViewGuest(content::BrowserContext* browser_context, | 241 WebViewGuest(content::BrowserContext* browser_context, |
232 int guest_instance_id); | 242 int guest_instance_id); |
233 | 243 |
234 virtual ~WebViewGuest(); | 244 virtual ~WebViewGuest(); |
235 | 245 |
| 246 // Returns the top level items (ignoring submenus) as Value. |
| 247 static scoped_ptr<base::ListValue> MenuModelToValue( |
| 248 const ui::SimpleMenuModel& menu_model); |
| 249 |
236 void AttachWebViewHelpers(content::WebContents* contents); | 250 void AttachWebViewHelpers(content::WebContents* contents); |
237 | 251 |
238 void OnWebViewNewWindowResponse(int new_window_instance_id, | 252 void OnWebViewNewWindowResponse(int new_window_instance_id, |
239 bool allow, | 253 bool allow, |
240 const std::string& user_input); | 254 const std::string& user_input); |
241 | 255 |
242 // WebContentsObserver implementation. | 256 // WebContentsObserver implementation. |
243 virtual void DidCommitProvisionalLoadForFrame( | 257 virtual void DidCommitProvisionalLoadForFrame( |
244 content::RenderFrameHost* render_frame_host, | 258 content::RenderFrameHost* render_frame_host, |
245 const GURL& url, | 259 const GURL& url, |
(...skipping 24 matching lines...) Expand all Loading... |
270 | 284 |
271 // Called when a redirect notification occurs. | 285 // Called when a redirect notification occurs. |
272 void LoadRedirect(const GURL& old_url, | 286 void LoadRedirect(const GURL& old_url, |
273 const GURL& new_url, | 287 const GURL& new_url, |
274 bool is_top_level); | 288 bool is_top_level); |
275 | 289 |
276 void PushWebViewStateToIOThread(); | 290 void PushWebViewStateToIOThread(); |
277 static void RemoveWebViewStateFromIOThread( | 291 static void RemoveWebViewStateFromIOThread( |
278 content::WebContents* web_contents); | 292 content::WebContents* web_contents); |
279 | 293 |
| 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 |
280 void LoadURLWithParams(const GURL& url, | 302 void LoadURLWithParams(const GURL& url, |
281 const content::Referrer& referrer, | 303 const content::Referrer& referrer, |
282 content::PageTransition transition_type, | 304 content::PageTransition transition_type, |
283 content::WebContents* web_contents); | 305 content::WebContents* web_contents); |
284 | 306 |
285 void RequestNewWindowPermission( | 307 void RequestNewWindowPermission( |
286 WindowOpenDisposition disposition, | 308 WindowOpenDisposition disposition, |
287 const gfx::Rect& initial_bounds, | 309 const gfx::Rect& initial_bounds, |
288 bool user_gesture, | 310 bool user_gesture, |
289 content::WebContents* new_contents); | 311 content::WebContents* new_contents); |
(...skipping 21 matching lines...) Expand all Loading... |
311 | 333 |
312 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); | 334 bool HandleKeyboardShortcuts(const content::NativeWebKeyboardEvent& event); |
313 | 335 |
314 void SetUpAutoSize(); | 336 void SetUpAutoSize(); |
315 | 337 |
316 ObserverList<ScriptExecutionObserver> script_observers_; | 338 ObserverList<ScriptExecutionObserver> script_observers_; |
317 scoped_ptr<ScriptExecutor> script_executor_; | 339 scoped_ptr<ScriptExecutor> script_executor_; |
318 | 340 |
319 content::NotificationRegistrar notification_registrar_; | 341 content::NotificationRegistrar notification_registrar_; |
320 | 342 |
| 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 |
321 // True if the user agent is overridden. | 347 // True if the user agent is overridden. |
322 bool is_overriding_user_agent_; | 348 bool is_overriding_user_agent_; |
323 | 349 |
| 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 |
324 // Stores the window name of the main frame of the guest. | 356 // Stores the window name of the main frame of the guest. |
325 std::string name_; | 357 std::string name_; |
326 | 358 |
327 // Handles find requests and replies for the webview find API. | 359 // Handles find requests and replies for the webview find API. |
328 WebViewFindHelper find_helper_; | 360 WebViewFindHelper find_helper_; |
329 | 361 |
330 // Handles the JavaScript dialog requests. | 362 // Handles the JavaScript dialog requests. |
331 JavaScriptDialogHelper javascript_dialog_helper_; | 363 JavaScriptDialogHelper javascript_dialog_helper_; |
332 | 364 |
333 // Handels permission requests. | 365 // Handels permission requests. |
334 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; | 366 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_; |
335 | 367 |
336 scoped_ptr<WebViewGuestDelegate> web_view_guest_delegate_; | |
337 | |
338 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, | 368 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, |
339 bool final_update); | 369 bool final_update); |
340 | 370 |
| 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 |
341 // Tracks the name, and target URL of the new window. Once the first | 381 // Tracks the name, and target URL of the new window. Once the first |
342 // navigation commits, we no longer track this information. | 382 // navigation commits, we no longer track this information. |
343 struct NewWindowInfo { | 383 struct NewWindowInfo { |
344 GURL url; | 384 GURL url; |
345 std::string name; | 385 std::string name; |
346 bool changed; | 386 bool changed; |
347 NewWindowInfo(const GURL& url, const std::string& name) : | 387 NewWindowInfo(const GURL& url, const std::string& name) : |
348 url(url), | 388 url(url), |
349 name(name), | 389 name(name), |
350 changed(false) {} | 390 changed(false) {} |
351 }; | 391 }; |
352 | 392 |
353 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; | 393 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; |
354 PendingWindowMap pending_new_windows_; | 394 PendingWindowMap pending_new_windows_; |
355 | 395 |
356 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); | 396 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); |
357 }; | 397 }; |
358 | 398 |
359 } // namespace extensions | 399 } // namespace extensions |
360 | 400 |
361 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ | 401 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ |
OLD | NEW |