OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/website_settings/permission_bubble_manager.h" | 5 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/user_metrics_action.h" | 8 #include "base/metrics/user_metrics_action.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/navigation_details.h" | 13 #include "content/public/browser/navigation_details.h" |
14 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
15 #include "url/origin.h" | 15 #include "url/origin.h" |
16 | 16 |
17 #if !defined(OS_ANDROID) | 17 #if !defined(OS_ANDROID) |
18 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
19 #endif | 19 #endif |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class CancelledRequest : public PermissionBubbleRequest { | 23 class CancelledRequest : public PermissionBubbleRequest { |
24 public: | 24 public: |
25 explicit CancelledRequest(PermissionBubbleRequest* cancelled) | 25 explicit CancelledRequest(PermissionBubbleRequest* cancelled) |
26 : icon_(cancelled->GetIconId()), | 26 : icon_(cancelled->GetIconId()), |
27 message_text_(cancelled->GetMessageText()), | 27 message_text_(cancelled->GetMessageText()), |
28 message_fragment_(cancelled->GetMessageTextFragment()), | 28 message_fragment_(cancelled->GetMessageTextFragment()), |
29 user_gesture_(cancelled->HasUserGesture()), | 29 user_gesture_(cancelled->HasUserGesture()), |
30 hostname_(cancelled->GetRequestingHostname()) {} | 30 origin_(cancelled->GetOrigin()) {} |
31 ~CancelledRequest() override {} | 31 ~CancelledRequest() override {} |
32 | 32 |
33 int GetIconId() const override { return icon_; } | 33 int GetIconId() const override { return icon_; } |
34 base::string16 GetMessageText() const override { return message_text_; } | 34 base::string16 GetMessageText() const override { return message_text_; } |
35 base::string16 GetMessageTextFragment() const override { | 35 base::string16 GetMessageTextFragment() const override { |
36 return message_fragment_; | 36 return message_fragment_; |
37 } | 37 } |
38 bool HasUserGesture() const override { return user_gesture_; } | 38 bool HasUserGesture() const override { return user_gesture_; } |
39 GURL GetRequestingHostname() const override { return hostname_; } | 39 GURL GetOrigin() const override { return origin_; } |
40 | 40 |
41 // These are all no-ops since the placeholder is non-forwarding. | 41 // These are all no-ops since the placeholder is non-forwarding. |
42 void PermissionGranted() override {} | 42 void PermissionGranted() override {} |
43 void PermissionDenied() override {} | 43 void PermissionDenied() override {} |
44 void Cancelled() override {} | 44 void Cancelled() override {} |
45 | 45 |
46 void RequestFinished() override { delete this; } | 46 void RequestFinished() override { delete this; } |
47 | 47 |
48 private: | 48 private: |
49 int icon_; | 49 int icon_; |
50 base::string16 message_text_; | 50 base::string16 message_text_; |
51 base::string16 message_fragment_; | 51 base::string16 message_fragment_; |
52 bool user_gesture_; | 52 bool user_gesture_; |
53 GURL hostname_; | 53 GURL origin_; |
54 }; | 54 }; |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 // PermissionBubbleManager::Observer ------------------------------------------- | 58 // PermissionBubbleManager::Observer ------------------------------------------- |
59 | 59 |
60 PermissionBubbleManager::Observer::~Observer() { | 60 PermissionBubbleManager::Observer::~Observer() { |
61 } | 61 } |
62 | 62 |
63 void PermissionBubbleManager::Observer::OnBubbleAdded() { | 63 void PermissionBubbleManager::Observer::OnBubbleAdded() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) { | 99 void PermissionBubbleManager::AddRequest(PermissionBubbleRequest* request) { |
100 content::RecordAction(base::UserMetricsAction("PermissionBubbleRequest")); | 100 content::RecordAction(base::UserMetricsAction("PermissionBubbleRequest")); |
101 // TODO(gbillock): is there a race between an early request on a | 101 // TODO(gbillock): is there a race between an early request on a |
102 // newly-navigated page and the to-be-cleaned-up requests on the previous | 102 // newly-navigated page and the to-be-cleaned-up requests on the previous |
103 // page? We should maybe listen to DidStartNavigationToPendingEntry (and | 103 // page? We should maybe listen to DidStartNavigationToPendingEntry (and |
104 // any other renderer-side nav initiations?). Double-check this for | 104 // any other renderer-side nav initiations?). Double-check this for |
105 // correct behavior on interstitials -- we probably want to basically queue | 105 // correct behavior on interstitials -- we probably want to basically queue |
106 // any request for which GetVisibleURL != GetLastCommittedURL. | 106 // any request for which GetVisibleURL != GetLastCommittedURL. |
107 request_url_ = web_contents()->GetLastCommittedURL(); | 107 request_url_ = web_contents()->GetLastCommittedURL(); |
108 bool is_main_frame = | 108 bool is_main_frame = url::Origin(request_url_) |
109 url::Origin(request_url_) | 109 .IsSameOriginWith(url::Origin(request->GetOrigin())); |
110 .IsSameOriginWith(url::Origin(request->GetRequestingHostname())); | |
111 | 110 |
112 // Don't re-add an existing request or one with a duplicate text request. | 111 // Don't re-add an existing request or one with a duplicate text request. |
113 // TODO(johnme): Instead of dropping duplicate requests, we should queue them | 112 // TODO(johnme): Instead of dropping duplicate requests, we should queue them |
114 // and eventually run their PermissionGranted/PermissionDenied/Cancelled | 113 // and eventually run their PermissionGranted/PermissionDenied/Cancelled |
115 // callback (crbug.com/577313). | 114 // callback (crbug.com/577313). |
116 bool same_object = false; | 115 bool same_object = false; |
117 if (ExistingRequest(request, requests_, &same_object) || | 116 if (ExistingRequest(request, requests_, &same_object) || |
118 ExistingRequest(request, queued_requests_, &same_object) || | 117 ExistingRequest(request, queued_requests_, &same_object) || |
119 ExistingRequest(request, queued_frame_requests_, &same_object)) { | 118 ExistingRequest(request, queued_frame_requests_, &same_object)) { |
120 if (!same_object) | 119 if (!same_object) |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 CHECK(same_object); | 405 CHECK(same_object); |
407 *same_object = false; | 406 *same_object = false; |
408 std::vector<PermissionBubbleRequest*>::const_iterator iter; | 407 std::vector<PermissionBubbleRequest*>::const_iterator iter; |
409 for (iter = queue.begin(); iter != queue.end(); iter++) { | 408 for (iter = queue.begin(); iter != queue.end(); iter++) { |
410 if (*iter == request) { | 409 if (*iter == request) { |
411 *same_object = true; | 410 *same_object = true; |
412 return true; | 411 return true; |
413 } | 412 } |
414 if ((*iter)->GetMessageTextFragment() == | 413 if ((*iter)->GetMessageTextFragment() == |
415 request->GetMessageTextFragment() && | 414 request->GetMessageTextFragment() && |
416 (*iter)->GetRequestingHostname() == request->GetRequestingHostname()) { | 415 (*iter)->GetOrigin() == request->GetOrigin()) { |
417 return true; | 416 return true; |
418 } | 417 } |
419 } | 418 } |
420 return false; | 419 return false; |
421 } | 420 } |
422 | 421 |
423 bool PermissionBubbleManager::HasUserGestureRequest( | 422 bool PermissionBubbleManager::HasUserGestureRequest( |
424 const std::vector<PermissionBubbleRequest*>& queue) { | 423 const std::vector<PermissionBubbleRequest*>& queue) { |
425 std::vector<PermissionBubbleRequest*>::const_iterator iter; | 424 std::vector<PermissionBubbleRequest*>::const_iterator iter; |
426 for (iter = queue.begin(); iter != queue.end(); iter++) { | 425 for (iter = queue.begin(); iter != queue.end(); iter++) { |
(...skipping 23 matching lines...) Expand all Loading... |
450 case DENY_ALL: | 449 case DENY_ALL: |
451 Deny(); | 450 Deny(); |
452 break; | 451 break; |
453 case DISMISS: | 452 case DISMISS: |
454 Closing(); | 453 Closing(); |
455 break; | 454 break; |
456 case NONE: | 455 case NONE: |
457 NOTREACHED(); | 456 NOTREACHED(); |
458 } | 457 } |
459 } | 458 } |
OLD | NEW |