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

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: Shorten UMA string literals 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 18 matching lines...) Expand all
29 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
30 #include "content/public/common/result_codes.h" 30 #include "content/public/common/result_codes.h"
31 #include "extensions/common/constants.h" 31 #include "extensions/common/constants.h"
32 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
33 33
34 #if defined(ENABLE_PLUGINS) 34 #if defined(ENABLE_PLUGINS)
35 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" 35 #include "chrome/browser/guestview/webview/plugin_permission_helper.h"
36 #endif 36 #endif
37 37
38 using content::WebContents; 38 using content::WebContents;
39 using content::UserMetricsAction;
39 40
40 namespace { 41 namespace {
41 42
42 static std::string TerminationStatusToString(base::TerminationStatus status) { 43 static std::string TerminationStatusToString(base::TerminationStatus status) {
43 switch (status) { 44 switch (status) {
44 case base::TERMINATION_STATUS_NORMAL_TERMINATION: 45 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
45 return "normal"; 46 return "normal";
46 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 47 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
47 case base::TERMINATION_STATUS_STILL_RUNNING: 48 case base::TERMINATION_STATUS_STILL_RUNNING:
48 return "abnormal"; 49 return "abnormal";
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return NULL; 140 return NULL;
140 return guest->AsWebView(); 141 return guest->AsWebView();
141 } 142 }
142 143
143 // static 144 // static
144 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { 145 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) {
145 GuestView* guest = GuestView::FromWebContents(contents); 146 GuestView* guest = GuestView::FromWebContents(contents);
146 return guest ? guest->AsWebView() : NULL; 147 return guest ? guest->AsWebView() : NULL;
147 } 148 }
148 149
150 // static
151 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info,
152 bool allow) {
153 if (allow) {
154 // Note that |allow| == true means the embedder explicitly allowed the
155 // request. For some requests they might still fail. An example of such
156 // scenario would be: an embedder allows geolocation request but doesn't
157 // have geolocation access on its own.
158 switch (info.permission_type) {
159 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD:
160 RecordAction(
161 UserMetricsAction("BrowserPlugin.PermissionAllow.Download"));
162 break;
163 case BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION:
164 RecordAction(
165 UserMetricsAction("BrowserPlugin.PermissionAllow.Geolocation"));
166 break;
167 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA:
168 RecordAction(
169 UserMetricsAction("BrowserPlugin.PermissionAllow.Media"));
170 break;
171 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
172 RecordAction(
173 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock"));
174 break;
175 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
176 RecordAction(
177 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow"));
178 break;
179 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
180 RecordAction(
181 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog"));
182 break;
183 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
184 break;
185 default: {
186 WebViewPermissionType webview_permission_type =
187 static_cast<WebViewPermissionType>(info.permission_type);
188 switch (webview_permission_type) {
189 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
190 RecordAction(
191 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad"));
192 break;
193 default:
194 break;
195 }
196 }
197 }
198 } else {
199 switch (info.permission_type) {
200 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD:
201 RecordAction(
202 UserMetricsAction("BrowserPlugin.PermissionDeny.Download"));
203 break;
204 case BROWSER_PLUGIN_PERMISSION_TYPE_GEOLOCATION:
205 RecordAction(
206 UserMetricsAction("BrowserPlugin.PermissionDeny.Geolocation"));
207 break;
208 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA:
209 RecordAction(
210 UserMetricsAction("BrowserPlugin.PermissionDeny.Media"));
211 break;
212 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
213 RecordAction(
214 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock"));
215 break;
216 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
217 RecordAction(
218 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow"));
219 break;
220 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
221 RecordAction(
222 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog"));
223 break;
224 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
225 break;
226 default: {
227 WebViewPermissionType webview_permission_type =
228 static_cast<WebViewPermissionType>(info.permission_type);
229 switch (webview_permission_type) {
230 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
231 RecordAction(
232 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad"));
233 break;
234 default:
235 break;
236 }
237 }
238 }
239 }
240 }
241
149 void WebViewGuest::Attach(WebContents* embedder_web_contents, 242 void WebViewGuest::Attach(WebContents* embedder_web_contents,
150 const base::DictionaryValue& args) { 243 const base::DictionaryValue& args) {
151 std::string user_agent_override; 244 std::string user_agent_override;
152 if (args.GetString(webview::kParameterUserAgentOverride, 245 if (args.GetString(webview::kParameterUserAgentOverride,
153 &user_agent_override)) { 246 &user_agent_override)) {
154 SetUserAgentOverride(user_agent_override); 247 SetUserAgentOverride(user_agent_override);
155 } else { 248 } else {
156 SetUserAgentOverride(""); 249 SetUserAgentOverride("");
157 } 250 }
158 251
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 bool allowed_by_default) { 404 bool allowed_by_default) {
312 // If there are too many pending permission requests then reject this request. 405 // If there are too many pending permission requests then reject this request.
313 if (pending_permission_requests_.size() >= 406 if (pending_permission_requests_.size() >=
314 webview::kMaxOutstandingPermissionRequests) { 407 webview::kMaxOutstandingPermissionRequests) {
315 callback.Run(false, std::string()); 408 callback.Run(false, std::string());
316 return true; 409 return true;
317 } 410 }
318 411
319 int request_id = next_permission_request_id_++; 412 int request_id = next_permission_request_id_++;
320 pending_permission_requests_[request_id] = 413 pending_permission_requests_[request_id] =
321 PermissionResponseInfo(callback, allowed_by_default); 414 PermissionResponseInfo(callback, permission_type, allowed_by_default);
322 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); 415 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy());
323 args->SetInteger(webview::kRequestId, request_id); 416 args->SetInteger(webview::kRequestId, request_id);
324 switch (permission_type) { 417 switch (permission_type) {
325 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: { 418 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: {
326 DispatchEvent(new GuestView::Event(webview::kEventNewWindow, 419 DispatchEvent(new GuestView::Event(webview::kEventNewWindow,
327 args.Pass())); 420 args.Pass()));
328 break; 421 break;
329 } 422 }
330 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { 423 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: {
331 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 424 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (request_itr == pending_permission_requests_.end()) 492 if (request_itr == pending_permission_requests_.end())
400 return SET_PERMISSION_INVALID; 493 return SET_PERMISSION_INVALID;
401 494
402 const PermissionResponseInfo& info = request_itr->second; 495 const PermissionResponseInfo& info = request_itr->second;
403 bool allow = (action == ALLOW) || 496 bool allow = (action == ALLOW) ||
404 ((action == DEFAULT) && info.allowed_by_default); 497 ((action == DEFAULT) && info.allowed_by_default);
405 498
406 info.callback.Run(allow, user_input); 499 info.callback.Run(allow, user_input);
407 pending_permission_requests_.erase(request_itr); 500 pending_permission_requests_.erase(request_itr);
408 501
502 // Only record user initiated (i.e. non-default) actions.
503 if (action != DEFAULT)
504 RecordUserInitiatedUMA(info, allow);
505
409 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED; 506 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED;
410 } 507 }
411 508
412 void WebViewGuest::SetUserAgentOverride( 509 void WebViewGuest::SetUserAgentOverride(
413 const std::string& user_agent_override) { 510 const std::string& user_agent_override) {
414 is_overriding_user_agent_ = !user_agent_override.empty(); 511 is_overriding_user_agent_ = !user_agent_override.empty();
415 if (is_overriding_user_agent_) { 512 if (is_overriding_user_agent_) {
416 content::RecordAction(content::UserMetricsAction( 513 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA"));
417 "WebView.Guest.OverrideUA"));
418 } 514 }
419 guest_web_contents()->SetUserAgentOverride(user_agent_override); 515 guest_web_contents()->SetUserAgentOverride(user_agent_override);
420 } 516 }
421 517
422 void WebViewGuest::Stop() { 518 void WebViewGuest::Stop() {
423 guest_web_contents()->Stop(); 519 guest_web_contents()->Stop();
424 } 520 }
425 521
426 void WebViewGuest::Terminate() { 522 void WebViewGuest::Terminate() {
427 content::RecordAction(content::UserMetricsAction("WebView.Guest.Terminate")); 523 content::RecordAction(UserMetricsAction("WebView.Guest.Terminate"));
428 base::ProcessHandle process_handle = 524 base::ProcessHandle process_handle =
429 guest_web_contents()->GetRenderProcessHost()->GetHandle(); 525 guest_web_contents()->GetRenderProcessHost()->GetHandle();
430 if (process_handle) 526 if (process_handle)
431 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); 527 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
432 } 528 }
433 529
434 bool WebViewGuest::ClearData(const base::Time remove_since, 530 bool WebViewGuest::ClearData(const base::Time remove_since,
435 uint32 removal_mask, 531 uint32 removal_mask,
436 const base::Closure& callback) { 532 const base::Closure& callback) {
533 content::RecordAction(UserMetricsAction("WebView.Guest.ClearData"));
437 content::StoragePartition* partition = 534 content::StoragePartition* partition =
438 content::BrowserContext::GetStoragePartition( 535 content::BrowserContext::GetStoragePartition(
439 web_contents()->GetBrowserContext(), 536 web_contents()->GetBrowserContext(),
440 web_contents()->GetSiteInstance()); 537 web_contents()->GetSiteInstance());
441 538
442 if (!partition) 539 if (!partition)
443 return false; 540 return false;
444 541
445 partition->ClearData( 542 partition->ClearData(
446 removal_mask, 543 removal_mask,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 const gfx::Size& new_size) { 678 const gfx::Size& new_size) {
582 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 679 scoped_ptr<DictionaryValue> args(new DictionaryValue());
583 args->SetInteger(webview::kOldHeight, old_size.height()); 680 args->SetInteger(webview::kOldHeight, old_size.height());
584 args->SetInteger(webview::kOldWidth, old_size.width()); 681 args->SetInteger(webview::kOldWidth, old_size.width());
585 args->SetInteger(webview::kNewHeight, new_size.height()); 682 args->SetInteger(webview::kNewHeight, new_size.height());
586 args->SetInteger(webview::kNewWidth, new_size.width()); 683 args->SetInteger(webview::kNewWidth, new_size.width());
587 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); 684 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass()));
588 } 685 }
589 686
590 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() 687 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo()
591 : allowed_by_default(false) { 688 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN),
689 allowed_by_default(false) {
592 } 690 }
593 691
594 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( 692 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo(
595 const PermissionResponseCallback& callback, 693 const PermissionResponseCallback& callback,
694 BrowserPluginPermissionType permission_type,
596 bool allowed_by_default) 695 bool allowed_by_default)
597 : callback(callback), 696 : callback(callback),
697 permission_type(permission_type),
598 allowed_by_default(allowed_by_default) { 698 allowed_by_default(allowed_by_default) {
599 } 699 }
600 700
601 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { 701 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
602 } 702 }
OLDNEW
« no previous file with comments | « chrome/browser/guestview/webview/webview_guest.h ('k') | content/browser/browser_plugin/browser_plugin_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698