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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); | 191 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); |
169 } | 192 } |
170 | 193 |
171 void WebViewGuest::RendererUnresponsive() { | 194 void WebViewGuest::RendererUnresponsive() { |
172 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 195 scoped_ptr<DictionaryValue> args(new DictionaryValue()); |
173 args->SetInteger(webview::kProcessId, | 196 args->SetInteger(webview::kProcessId, |
174 guest_web_contents()->GetRenderProcessHost()->GetID()); | 197 guest_web_contents()->GetRenderProcessHost()->GetID()); |
175 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); | 198 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); |
176 } | 199 } |
177 | 200 |
| 201 bool WebViewGuest::RequestPermission( |
| 202 BrowserPluginPermissionType permission_type, |
| 203 const base::DictionaryValue& request_info, |
| 204 const PermissionResponseCallback& callback) { |
| 205 int request_id = next_permission_request_id_++; |
| 206 pending_permission_requests_[request_id] = callback; |
| 207 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); |
| 208 args->SetInteger(webview::kRequestId, request_id); |
| 209 switch (permission_type) { |
| 210 case BrowserPluginPermissionTypeNewWindow: { |
| 211 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, |
| 212 args.Pass())); |
| 213 break; |
| 214 } |
| 215 case BrowserPluginPermissionTypeJavaScriptDialog: { |
| 216 DispatchEvent(new GuestView::Event(webview::kEventDialog, |
| 217 args.Pass())); |
| 218 break; |
| 219 } |
| 220 default: { |
| 221 args->SetString(webview::kPermission, |
| 222 PermissionTypeToString(permission_type)); |
| 223 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest, |
| 224 args.Pass())); |
| 225 break; |
| 226 } |
| 227 } |
| 228 return true; |
| 229 } |
| 230 |
178 void WebViewGuest::Observe(int type, | 231 void WebViewGuest::Observe(int type, |
179 const content::NotificationSource& source, | 232 const content::NotificationSource& source, |
180 const content::NotificationDetails& details) { | 233 const content::NotificationDetails& details) { |
181 switch (type) { | 234 switch (type) { |
182 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 235 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
183 DCHECK_EQ(content::Source<WebContents>(source).ptr(), | 236 DCHECK_EQ(content::Source<WebContents>(source).ptr(), |
184 guest_web_contents()); | 237 guest_web_contents()); |
185 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) | 238 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) |
186 LoadHandlerCalled(); | 239 LoadHandlerCalled(); |
187 break; | 240 break; |
(...skipping 20 matching lines...) Expand all Loading... |
208 guest_web_contents()->GetController().GoToOffset(relative_index); | 261 guest_web_contents()->GetController().GoToOffset(relative_index); |
209 } | 262 } |
210 | 263 |
211 void WebViewGuest::Reload() { | 264 void WebViewGuest::Reload() { |
212 // TODO(fsamuel): Don't check for repost because we don't want to show | 265 // TODO(fsamuel): Don't check for repost because we don't want to show |
213 // Chromium's repost warning. We might want to implement a separate API | 266 // Chromium's repost warning. We might want to implement a separate API |
214 // for registering a callback if a repost is about to happen. | 267 // for registering a callback if a repost is about to happen. |
215 guest_web_contents()->GetController().Reload(false); | 268 guest_web_contents()->GetController().Reload(false); |
216 } | 269 } |
217 | 270 |
| 271 bool WebViewGuest::SetPermission(int request_id, |
| 272 bool should_allow, |
| 273 const std::string& user_input) { |
| 274 RequestMap::iterator request_itr = |
| 275 pending_permission_requests_.find(request_id); |
| 276 |
| 277 if (request_itr == pending_permission_requests_.end()) |
| 278 return false; |
| 279 |
| 280 request_itr->second.Run(should_allow, user_input); |
| 281 pending_permission_requests_.erase(request_itr); |
| 282 return true; |
| 283 } |
| 284 |
218 void WebViewGuest::Stop() { | 285 void WebViewGuest::Stop() { |
219 guest_web_contents()->Stop(); | 286 guest_web_contents()->Stop(); |
220 } | 287 } |
221 | 288 |
222 void WebViewGuest::Terminate() { | 289 void WebViewGuest::Terminate() { |
223 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate")); | 290 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate")); |
224 base::ProcessHandle process_handle = | 291 base::ProcessHandle process_handle = |
225 guest_web_contents()->GetRenderProcessHost()->GetHandle(); | 292 guest_web_contents()->GetRenderProcessHost()->GetHandle(); |
226 if (process_handle) | 293 if (process_handle) |
227 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); | 294 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 void WebViewGuest::RemoveWebViewFromExtensionRendererState( | 399 void WebViewGuest::RemoveWebViewFromExtensionRendererState( |
333 WebContents* web_contents) { | 400 WebContents* web_contents) { |
334 content::BrowserThread::PostTask( | 401 content::BrowserThread::PostTask( |
335 content::BrowserThread::IO, FROM_HERE, | 402 content::BrowserThread::IO, FROM_HERE, |
336 base::Bind( | 403 base::Bind( |
337 &ExtensionRendererState::RemoveWebView, | 404 &ExtensionRendererState::RemoveWebView, |
338 base::Unretained(ExtensionRendererState::GetInstance()), | 405 base::Unretained(ExtensionRendererState::GetInstance()), |
339 web_contents->GetRenderProcessHost()->GetID(), | 406 web_contents->GetRenderProcessHost()->GetID(), |
340 web_contents->GetRoutingID())); | 407 web_contents->GetRoutingID())); |
341 } | 408 } |
OLD | NEW |