OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/content_settings/tab_specific_content_settings.h" | 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
43 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
44 #include "content/public/browser/web_contents_delegate.h" | 44 #include "content/public/browser/web_contents_delegate.h" |
45 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 45 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
46 #include "net/cookies/canonical_cookie.h" | 46 #include "net/cookies/canonical_cookie.h" |
47 #include "storage/common/fileapi/file_system_types.h" | 47 #include "storage/common/fileapi/file_system_types.h" |
48 | 48 |
49 using content::BrowserThread; | 49 using content::BrowserThread; |
50 using content::NavigationController; | 50 using content::NavigationController; |
51 using content::NavigationEntry; | 51 using content::NavigationEntry; |
52 using content::RenderViewHost; | |
53 using content::WebContents; | 52 using content::WebContents; |
54 | 53 |
55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); | 54 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 // Returns the object given a render frame's id. | |
60 TabSpecificContentSettings* GetForFrame(int render_process_id, | |
61 int render_frame_id) { | |
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
63 | |
64 content::RenderFrameHost* frame = content::RenderFrameHost::FromID( | |
65 render_process_id, render_frame_id); | |
66 WebContents* web_contents = WebContents::FromRenderFrameHost(frame); | |
67 if (!web_contents) | |
68 return nullptr; | |
69 | |
70 return TabSpecificContentSettings::FromWebContents(web_contents); | |
71 } | |
72 | |
73 ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( | 58 ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( |
74 const content::LoadCommittedDetails& details) { | 59 const content::LoadCommittedDetails& details) { |
75 ContentSettingsUsagesState::CommittedDetails committed_details; | 60 ContentSettingsUsagesState::CommittedDetails committed_details; |
76 committed_details.current_url_valid = !!details.entry; | 61 committed_details.current_url_valid = !!details.entry; |
77 if (details.entry) | 62 if (details.entry) |
78 committed_details.current_url = details.entry->GetURL(); | 63 committed_details.current_url = details.entry->GetURL(); |
79 committed_details.previous_url = details.previous_url; | 64 committed_details.previous_url = details.previous_url; |
80 return committed_details; | 65 return committed_details; |
81 } | 66 } |
82 | 67 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 111 |
127 observer_.Add(Profile::FromBrowserContext(tab->GetBrowserContext()) | 112 observer_.Add(Profile::FromBrowserContext(tab->GetBrowserContext()) |
128 ->GetHostContentSettingsMap()); | 113 ->GetHostContentSettingsMap()); |
129 } | 114 } |
130 | 115 |
131 TabSpecificContentSettings::~TabSpecificContentSettings() { | 116 TabSpecificContentSettings::~TabSpecificContentSettings() { |
132 FOR_EACH_OBSERVER( | 117 FOR_EACH_OBSERVER( |
133 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); | 118 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); |
134 } | 119 } |
135 | 120 |
136 // static | 121 TabSpecificContentSettings* TabSpecificContentSettings::GetForFrame( |
137 TabSpecificContentSettings* TabSpecificContentSettings::Get( | 122 int render_process_id, |
138 int render_process_id, int render_view_id) { | 123 int render_frame_id) { |
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
140 | 125 |
141 RenderViewHost* view = RenderViewHost::FromID(render_process_id, | 126 content::RenderFrameHost* frame = content::RenderFrameHost::FromID( |
142 render_view_id); | 127 render_process_id, render_frame_id); |
143 if (!view) | 128 WebContents* web_contents = WebContents::FromRenderFrameHost(frame); |
144 return NULL; | |
145 | |
146 WebContents* web_contents = WebContents::FromRenderViewHost(view); | |
147 if (!web_contents) | 129 if (!web_contents) |
148 return NULL; | 130 return nullptr; |
149 | 131 |
150 return TabSpecificContentSettings::FromWebContents(web_contents); | 132 return TabSpecificContentSettings::FromWebContents(web_contents); |
151 } | 133 } |
152 | 134 |
153 // static | 135 // static |
154 void TabSpecificContentSettings::CookiesRead(int render_process_id, | 136 void TabSpecificContentSettings::CookiesRead(int render_process_id, |
155 int render_frame_id, | 137 int render_frame_id, |
156 const GURL& url, | 138 const GURL& url, |
157 const GURL& frame_url, | 139 const GURL& frame_url, |
158 const net::CookieList& cookie_list, | 140 const net::CookieList& cookie_list, |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 804 |
823 void TabSpecificContentSettings::GeolocationDidNavigate( | 805 void TabSpecificContentSettings::GeolocationDidNavigate( |
824 const content::LoadCommittedDetails& details) { | 806 const content::LoadCommittedDetails& details) { |
825 geolocation_usages_state_.DidNavigate(GetCommittedDetails(details)); | 807 geolocation_usages_state_.DidNavigate(GetCommittedDetails(details)); |
826 } | 808 } |
827 | 809 |
828 void TabSpecificContentSettings::MidiDidNavigate( | 810 void TabSpecificContentSettings::MidiDidNavigate( |
829 const content::LoadCommittedDetails& details) { | 811 const content::LoadCommittedDetails& details) { |
830 midi_usages_state_.DidNavigate(GetCommittedDetails(details)); | 812 midi_usages_state_.DidNavigate(GetCommittedDetails(details)); |
831 } | 813 } |
OLD | NEW |