| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/guestview/webview/webview_guest.h" | 5 #include "chrome/browser/guestview/webview/webview_guest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 8 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 9 #include "chrome/browser/extensions/extension_renderer_state.h" | 9 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 10 #include "chrome/browser/extensions/script_executor.h" | 10 #include "chrome/browser/extensions/script_executor.h" |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 11 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 12 #include "chrome/browser/guestview/guestview_constants.h" | 12 #include "chrome/browser/guestview/guestview_constants.h" |
| 13 #include "chrome/browser/guestview/webview/webview_constants.h" | 13 #include "chrome/browser/guestview/webview/webview_constants.h" |
| 14 #include "chrome/browser/guestview/webview/webview_permission_types.h" |
| 14 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/native_web_keyboard_event.h" | 17 #include "content/public/browser/native_web_keyboard_event.h" |
| 17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 19 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/resource_request_details.h" | 22 #include "content/public/browser/resource_request_details.h" |
| 22 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 23 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/result_codes.h" | 27 #include "content/public/common/result_codes.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 | 29 |
| 30 #if defined(ENABLE_PLUGINS) |
| 31 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" |
| 32 #endif |
| 33 |
| 29 using content::WebContents; | 34 using content::WebContents; |
| 30 | 35 |
| 31 namespace { | 36 namespace { |
| 32 | 37 |
| 33 static std::string TerminationStatusToString(base::TerminationStatus status) { | 38 static std::string TerminationStatusToString(base::TerminationStatus status) { |
| 34 switch (status) { | 39 switch (status) { |
| 35 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 40 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 36 return "normal"; | 41 return "normal"; |
| 37 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 42 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 38 case base::TERMINATION_STATUS_STILL_RUNNING: | 43 case base::TERMINATION_STATUS_STILL_RUNNING: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 return webview::kPermissionTypeGeolocation; | 61 return webview::kPermissionTypeGeolocation; |
| 57 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: | 62 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA: |
| 58 return webview::kPermissionTypeMedia; | 63 return webview::kPermissionTypeMedia; |
| 59 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: | 64 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: |
| 60 return webview::kPermissionTypeNewWindow; | 65 return webview::kPermissionTypeNewWindow; |
| 61 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: | 66 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: |
| 62 return webview::kPermissionTypePointerLock; | 67 return webview::kPermissionTypePointerLock; |
| 63 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 68 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 64 return webview::kPermissionTypeDialog; | 69 return webview::kPermissionTypeDialog; |
| 65 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: | 70 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: |
| 66 default: | |
| 67 NOTREACHED(); | 71 NOTREACHED(); |
| 68 break; | 72 break; |
| 73 default: { |
| 74 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type); |
| 75 switch (webview) { |
| 76 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 77 return webview::kPermissionTypeLoadPlugin; |
| 78 } |
| 79 NOTREACHED(); |
| 80 } |
| 69 } | 81 } |
| 70 return std::string(); | 82 return std::string(); |
| 71 } | 83 } |
| 72 | 84 |
| 73 void RemoveWebViewEventListenersOnIOThread( | 85 void RemoveWebViewEventListenersOnIOThread( |
| 74 void* profile, | 86 void* profile, |
| 75 const std::string& extension_id, | 87 const std::string& extension_id, |
| 76 int embedder_process_id, | 88 int embedder_process_id, |
| 77 int view_instance_id) { | 89 int view_instance_id) { |
| 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 90 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 79 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 91 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
| 80 profile, | 92 profile, |
| 81 extension_id, | 93 extension_id, |
| 82 embedder_process_id, | 94 embedder_process_id, |
| 83 view_instance_id); | 95 view_instance_id); |
| 84 } | 96 } |
| 85 | 97 |
| 86 void AttachWebViewHelpers(WebContents* contents) { | 98 void AttachWebViewHelpers(WebContents* contents) { |
| 87 FaviconTabHelper::CreateForWebContents(contents); | 99 FaviconTabHelper::CreateForWebContents(contents); |
| 100 #if defined(ENABLE_PLUGINS) |
| 101 PluginPermissionHelper::CreateForWebContents(contents); |
| 102 #endif |
| 88 } | 103 } |
| 89 | 104 |
| 90 } // namespace | 105 } // namespace |
| 91 | 106 |
| 92 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) | 107 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) |
| 93 : GuestView(guest_web_contents), | 108 : GuestView(guest_web_contents), |
| 94 WebContentsObserver(guest_web_contents), | 109 WebContentsObserver(guest_web_contents), |
| 95 script_executor_(new extensions::ScriptExecutor(guest_web_contents, | 110 script_executor_(new extensions::ScriptExecutor(guest_web_contents, |
| 96 &script_observers_)), | 111 &script_observers_)), |
| 97 next_permission_request_id_(0), | 112 next_permission_request_id_(0), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 109 | 124 |
| 110 // static | 125 // static |
| 111 WebViewGuest* WebViewGuest::From(int embedder_process_id, | 126 WebViewGuest* WebViewGuest::From(int embedder_process_id, |
| 112 int guest_instance_id) { | 127 int guest_instance_id) { |
| 113 GuestView* guest = GuestView::From(embedder_process_id, guest_instance_id); | 128 GuestView* guest = GuestView::From(embedder_process_id, guest_instance_id); |
| 114 if (!guest) | 129 if (!guest) |
| 115 return NULL; | 130 return NULL; |
| 116 return guest->AsWebView(); | 131 return guest->AsWebView(); |
| 117 } | 132 } |
| 118 | 133 |
| 134 // static |
| 135 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { |
| 136 GuestView* guest = GuestView::FromWebContents(contents); |
| 137 return guest ? guest->AsWebView() : NULL; |
| 138 } |
| 139 |
| 119 void WebViewGuest::Attach(WebContents* embedder_web_contents, | 140 void WebViewGuest::Attach(WebContents* embedder_web_contents, |
| 120 const std::string& extension_id, | 141 const std::string& extension_id, |
| 121 const base::DictionaryValue& args) { | 142 const base::DictionaryValue& args) { |
| 122 std::string user_agent_override; | 143 std::string user_agent_override; |
| 123 if (args.GetString(webview::kParameterUserAgentOverride, | 144 if (args.GetString(webview::kParameterUserAgentOverride, |
| 124 &user_agent_override)) { | 145 &user_agent_override)) { |
| 125 SetUserAgentOverride(user_agent_override); | 146 SetUserAgentOverride(user_agent_override); |
| 126 } else { | 147 } else { |
| 127 SetUserAgentOverride(""); | 148 SetUserAgentOverride(""); |
| 128 } | 149 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 520 |
| 500 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 521 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 501 const gfx::Size& new_size) { | 522 const gfx::Size& new_size) { |
| 502 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 523 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
| 503 args->SetInteger(webview::kOldHeight, old_size.height()); | 524 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 504 args->SetInteger(webview::kOldWidth, old_size.width()); | 525 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 505 args->SetInteger(webview::kNewHeight, new_size.height()); | 526 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 506 args->SetInteger(webview::kNewWidth, new_size.width()); | 527 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 507 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); | 528 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); |
| 508 } | 529 } |
| OLD | NEW |