Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/guestview/webview/webview_guest.cc

Issue 69913002: Add UMA for <webview> APIs: a. ClearData, b. when Permission request is allowed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refine by permission granularity. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 9 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
10 #include "chrome/browser/extensions/extension_renderer_state.h" 10 #include "chrome/browser/extensions/extension_renderer_state.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 305 }
306 306
307 bool WebViewGuest::RequestPermission( 307 bool WebViewGuest::RequestPermission(
308 BrowserPluginPermissionType permission_type, 308 BrowserPluginPermissionType permission_type,
309 const base::DictionaryValue& request_info, 309 const base::DictionaryValue& request_info,
310 const PermissionResponseCallback& callback, 310 const PermissionResponseCallback& callback,
311 bool allowed_by_default) { 311 bool allowed_by_default) {
312 // If there are too many pending permission requests then reject this request. 312 // If there are too many pending permission requests then reject this request.
313 if (pending_permission_requests_.size() >= 313 if (pending_permission_requests_.size() >=
314 webview::kMaxOutstandingPermissionRequests) { 314 webview::kMaxOutstandingPermissionRequests) {
315 callback.Run(false, std::string()); 315 callback.Run(false, std::string(), false);
316 return true; 316 return true;
317 } 317 }
318 318
319 int request_id = next_permission_request_id_++; 319 int request_id = next_permission_request_id_++;
320 pending_permission_requests_[request_id] = 320 pending_permission_requests_[request_id] =
321 PermissionResponseInfo(callback, allowed_by_default); 321 PermissionResponseInfo(callback, allowed_by_default);
322 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); 322 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy());
323 args->SetInteger(webview::kRequestId, request_id); 323 args->SetInteger(webview::kRequestId, request_id);
324 switch (permission_type) { 324 switch (permission_type) {
325 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: { 325 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: {
326 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, 326 DispatchEvent(new GuestView::Event(webview::kEventNewWindow,
327 args.Pass())); 327 args.Pass()));
328 break; 328 break;
329 } 329 }
330 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { 330 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: {
331 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 331 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
332 if (channel > chrome::VersionInfo::CHANNEL_DEV) { 332 if (channel > chrome::VersionInfo::CHANNEL_DEV) {
333 // 'dialog' API is not available in stable/beta. 333 // 'dialog' API is not available in stable/beta.
334 callback.Run(false, std::string()); 334 callback.Run(false, std::string(), false);
335 return true; 335 return true;
336 } 336 }
337 DispatchEvent(new GuestView::Event(webview::kEventDialog, 337 DispatchEvent(new GuestView::Event(webview::kEventDialog,
338 args.Pass())); 338 args.Pass()));
339 break; 339 break;
340 } 340 }
341 default: { 341 default: {
342 args->SetString(webview::kPermission, 342 args->SetString(webview::kPermission,
343 PermissionTypeToString(permission_type)); 343 PermissionTypeToString(permission_type));
344 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest, 344 DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 RequestMap::iterator request_itr = 396 RequestMap::iterator request_itr =
397 pending_permission_requests_.find(request_id); 397 pending_permission_requests_.find(request_id);
398 398
399 if (request_itr == pending_permission_requests_.end()) 399 if (request_itr == pending_permission_requests_.end())
400 return SET_PERMISSION_INVALID; 400 return SET_PERMISSION_INVALID;
401 401
402 const PermissionResponseInfo& info = request_itr->second; 402 const PermissionResponseInfo& info = request_itr->second;
403 bool allow = (action == ALLOW) || 403 bool allow = (action == ALLOW) ||
404 ((action == DEFAULT) && info.allowed_by_default); 404 ((action == DEFAULT) && info.allowed_by_default);
405 405
406 info.callback.Run(allow, user_input); 406 info.callback.Run(allow, user_input, action != DEFAULT);
407 pending_permission_requests_.erase(request_itr); 407 pending_permission_requests_.erase(request_itr);
408 408
409 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED; 409 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED;
410 } 410 }
411 411
412 void WebViewGuest::SetUserAgentOverride( 412 void WebViewGuest::SetUserAgentOverride(
413 const std::string& user_agent_override) { 413 const std::string& user_agent_override) {
414 is_overriding_user_agent_ = !user_agent_override.empty(); 414 is_overriding_user_agent_ = !user_agent_override.empty();
415 if (is_overriding_user_agent_) { 415 if (is_overriding_user_agent_) {
416 content::RecordAction(content::UserMetricsAction( 416 content::RecordAction(content::UserMetricsAction(
(...skipping 10 matching lines...) Expand all
427 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate")); 427 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate"));
428 base::ProcessHandle process_handle = 428 base::ProcessHandle process_handle =
429 guest_web_contents()->GetRenderProcessHost()->GetHandle(); 429 guest_web_contents()->GetRenderProcessHost()->GetHandle();
430 if (process_handle) 430 if (process_handle)
431 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); 431 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
432 } 432 }
433 433
434 bool WebViewGuest::ClearData(const base::Time remove_since, 434 bool WebViewGuest::ClearData(const base::Time remove_since,
435 uint32 removal_mask, 435 uint32 removal_mask,
436 const base::Closure& callback) { 436 const base::Closure& callback) {
437 content::RecordAction(content::UserMetricsAction("WebView.Guest.ClearData"));
437 content::StoragePartition* partition = 438 content::StoragePartition* partition =
438 content::BrowserContext::GetStoragePartition( 439 content::BrowserContext::GetStoragePartition(
439 web_contents()->GetBrowserContext(), 440 web_contents()->GetBrowserContext(),
440 web_contents()->GetSiteInstance()); 441 web_contents()->GetSiteInstance());
441 442
442 if (!partition) 443 if (!partition)
443 return false; 444 return false;
444 445
445 partition->ClearData( 446 partition->ClearData(
446 removal_mask, 447 removal_mask,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 594
594 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( 595 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo(
595 const PermissionResponseCallback& callback, 596 const PermissionResponseCallback& callback,
596 bool allowed_by_default) 597 bool allowed_by_default)
597 : callback(callback), 598 : callback(callback),
598 allowed_by_default(allowed_by_default) { 599 allowed_by_default(allowed_by_default) {
599 } 600 }
600 601
601 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { 602 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
602 } 603 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698