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 "chrome/browser/extensions/api/web_request/web_request_api.h" | 7 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
8 #include "chrome/browser/extensions/extension_renderer_state.h" | 8 #include "chrome/browser/extensions/extension_renderer_state.h" |
9 #include "chrome/browser/extensions/script_executor.h" | 9 #include "chrome/browser/extensions/script_executor.h" |
10 #include "chrome/browser/guestview/guestview_constants.h" | 10 #include "chrome/browser/guestview/guestview_constants.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 return "killed"; | 36 return "killed"; |
37 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 37 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
38 return "crashed"; | 38 return "crashed"; |
39 case base::TERMINATION_STATUS_MAX_ENUM: | 39 case base::TERMINATION_STATUS_MAX_ENUM: |
40 break; | 40 break; |
41 } | 41 } |
42 NOTREACHED() << "Unknown Termination Status."; | 42 NOTREACHED() << "Unknown Termination Status."; |
43 return "unknown"; | 43 return "unknown"; |
44 } | 44 } |
45 | 45 |
| 46 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { |
| 47 switch (type) { |
| 48 case BrowserPluginPermissionTypeDownload: |
| 49 return webview::kPermissionTypeDownload; |
| 50 case BrowserPluginPermissionTypeGeolocation: |
| 51 return webview::kPermissionTypeGeolocation; |
| 52 case BrowserPluginPermissionTypeMedia: |
| 53 return webview::kPermissionTypeMedia; |
| 54 case BrowserPluginPermissionTypeNewWindow: |
| 55 return webview::kPermissionTypeNewWindow; |
| 56 case BrowserPluginPermissionTypePointerLock: |
| 57 return webview::kPermissionTypePointerLock; |
| 58 case BrowserPluginPermissionTypeJavaScriptDialog: |
| 59 return webview::kPermissionTypeDialog; |
| 60 case BrowserPluginPermissionTypeUnknown: |
| 61 default: |
| 62 NOTREACHED(); |
| 63 break; |
| 64 } |
| 65 return std::string(); |
| 66 } |
| 67 |
46 void RemoveWebViewEventListenersOnIOThread( | 68 void RemoveWebViewEventListenersOnIOThread( |
47 void* profile, | 69 void* profile, |
48 const std::string& extension_id, | 70 const std::string& extension_id, |
49 int embedder_process_id, | 71 int embedder_process_id, |
50 int guest_instance_id) { | 72 int guest_instance_id) { |
51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 73 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
52 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 74 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
53 profile, extension_id, embedder_process_id, guest_instance_id); | 75 profile, extension_id, embedder_process_id, guest_instance_id); |
54 } | 76 } |
55 | 77 |
56 } // namespace | 78 } // namespace |
57 | 79 |
58 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) | 80 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) |
59 : GuestView(guest_web_contents), | 81 : GuestView(guest_web_contents), |
60 WebContentsObserver(guest_web_contents), | 82 WebContentsObserver(guest_web_contents), |
61 script_executor_(new extensions::ScriptExecutor(guest_web_contents, | 83 script_executor_(new extensions::ScriptExecutor(guest_web_contents, |
62 &script_observers_)) { | 84 &script_observers_)), |
| 85 next_permission_request_id_(0) { |
63 notification_registrar_.Add( | 86 notification_registrar_.Add( |
64 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 87 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
65 content::Source<WebContents>(guest_web_contents)); | 88 content::Source<WebContents>(guest_web_contents)); |
66 | 89 |
67 notification_registrar_.Add( | 90 notification_registrar_.Add( |
68 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 91 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
69 content::Source<WebContents>(guest_web_contents)); | 92 content::Source<WebContents>(guest_web_contents)); |
70 } | 93 } |
71 | 94 |
72 // static | 95 // static |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); | 192 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); |
170 } | 193 } |
171 | 194 |
172 void WebViewGuest::RendererUnresponsive() { | 195 void WebViewGuest::RendererUnresponsive() { |
173 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 196 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
174 args->SetInteger(webview::kProcessId, | 197 args->SetInteger(webview::kProcessId, |
175 guest_web_contents()->GetRenderProcessHost()->GetID()); | 198 guest_web_contents()->GetRenderProcessHost()->GetID()); |
176 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); | 199 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); |
177 } | 200 } |
178 | 201 |
| 202 bool WebViewGuest::RequestPermission( |
| 203 BrowserPluginPermissionType permission_type, |
| 204 const base::DictionaryValue& request_info, |
| 205 const PermissionResponseCallback& callback) { |
| 206 int request_id = next_permission_request_id_++; |
| 207 pending_permission_requests_[request_id] = callback; |
| 208 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); |
| 209 args->SetInteger(webview::kRequestId, request_id); |
| 210 switch (permission_type) { |
| 211 case BrowserPluginPermissionTypeNewWindow: { |
| 212 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, |
| 213 args.Pass())); |
| 214 break; |
| 215 } |
| 216 case BrowserPluginPermissionTypeJavaScriptDialog: { |
| 217 DispatchEvent(new GuestView::Event(webview::kEventDialog, |
| 218 args.Pass())); |
| 219 break; |
| 220 } |
| 221 default: { |
| 222 args->SetString(webview::kPermission, |
| 223 PermissionTypeToString(permission_type)); |
| 224 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest, |
| 225 args.Pass())); |
| 226 break; |
| 227 } |
| 228 } |
| 229 return true; |
| 230 } |
| 231 |
179 void WebViewGuest::Observe(int type, | 232 void WebViewGuest::Observe(int type, |
180 const content::NotificationSource& source, | 233 const content::NotificationSource& source, |
181 const content::NotificationDetails& details) { | 234 const content::NotificationDetails& details) { |
182 switch (type) { | 235 switch (type) { |
183 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 236 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
184 DCHECK_EQ(content::Source<WebContents>(source).ptr(), | 237 DCHECK_EQ(content::Source<WebContents>(source).ptr(), |
185 guest_web_contents()); | 238 guest_web_contents()); |
186 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) | 239 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) |
187 LoadHandlerCalled(); | 240 LoadHandlerCalled(); |
188 break; | 241 break; |
(...skipping 20 matching lines...) Expand all Loading... |
209 guest_web_contents()->GetController().GoToOffset(relative_index); | 262 guest_web_contents()->GetController().GoToOffset(relative_index); |
210 } | 263 } |
211 | 264 |
212 void WebViewGuest::Reload() { | 265 void WebViewGuest::Reload() { |
213 // TODO(fsamuel): Don't check for repost because we don't want to show | 266 // TODO(fsamuel): Don't check for repost because we don't want to show |
214 // Chromium's repost warning. We might want to implement a separate API | 267 // Chromium's repost warning. We might want to implement a separate API |
215 // for registering a callback if a repost is about to happen. | 268 // for registering a callback if a repost is about to happen. |
216 guest_web_contents()->GetController().Reload(false); | 269 guest_web_contents()->GetController().Reload(false); |
217 } | 270 } |
218 | 271 |
| 272 bool WebViewGuest::SetPermission(int request_id, |
| 273 bool should_allow, |
| 274 const std::string& user_input) { |
| 275 RequestMap::iterator request_itr = |
| 276 pending_permission_requests_.find(request_id); |
| 277 |
| 278 if (request_itr == pending_permission_requests_.end()) |
| 279 return false; |
| 280 |
| 281 request_itr->second.Run(should_allow, user_input); |
| 282 pending_permission_requests_.erase(request_itr); |
| 283 return true; |
| 284 } |
| 285 |
219 void WebViewGuest::Stop() { | 286 void WebViewGuest::Stop() { |
220 guest_web_contents()->Stop(); | 287 guest_web_contents()->Stop(); |
221 } | 288 } |
222 | 289 |
223 void WebViewGuest::Terminate() { | 290 void WebViewGuest::Terminate() { |
224 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate")); | 291 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate")); |
225 base::ProcessHandle process_handle = | 292 base::ProcessHandle process_handle = |
226 guest_web_contents()->GetRenderProcessHost()->GetHandle(); | 293 guest_web_contents()->GetRenderProcessHost()->GetHandle(); |
227 if (process_handle) | 294 if (process_handle) |
228 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); | 295 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 void WebViewGuest::RemoveWebViewFromExtensionRendererState( | 401 void WebViewGuest::RemoveWebViewFromExtensionRendererState( |
335 WebContents* web_contents) { | 402 WebContents* web_contents) { |
336 content::BrowserThread::PostTask( | 403 content::BrowserThread::PostTask( |
337 content::BrowserThread::IO, FROM_HERE, | 404 content::BrowserThread::IO, FROM_HERE, |
338 base::Bind( | 405 base::Bind( |
339 &ExtensionRendererState::RemoveWebView, | 406 &ExtensionRendererState::RemoveWebView, |
340 base::Unretained(ExtensionRendererState::GetInstance()), | 407 base::Unretained(ExtensionRendererState::GetInstance()), |
341 web_contents->GetRenderProcessHost()->GetID(), | 408 web_contents->GetRenderProcessHost()->GetID(), |
342 web_contents->GetRoutingID())); | 409 web_contents->GetRoutingID())); |
343 } | 410 } |
OLD | NEW |