| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/declarative_content/declarative_content_
css_condition_tracker.h" | 5 #include "chrome/browser/extensions/api/declarative_content/declarative_content_
css_condition_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" | 14 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
| 15 #include "chrome/browser/extensions/api/declarative_content/content_predicate_ev
aluator.h" | 15 #include "chrome/browser/extensions/api/declarative_content/content_predicate_ev
aluator.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_handle.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 21 #include "extensions/common/extension_messages.h" | 21 #include "extensions/common/extension_messages.h" |
| 22 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
| 23 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 : WebContentsObserver(contents), | 91 : WebContentsObserver(contents), |
| 92 request_evaluation_(request_evaluation), | 92 request_evaluation_(request_evaluation), |
| 93 web_contents_destroyed_(web_contents_destroyed) { | 93 web_contents_destroyed_(web_contents_destroyed) { |
| 94 } | 94 } |
| 95 | 95 |
| 96 DeclarativeContentCssConditionTracker::PerWebContentsTracker:: | 96 DeclarativeContentCssConditionTracker::PerWebContentsTracker:: |
| 97 ~PerWebContentsTracker() { | 97 ~PerWebContentsTracker() { |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DeclarativeContentCssConditionTracker::PerWebContentsTracker:: | 100 void DeclarativeContentCssConditionTracker::PerWebContentsTracker:: |
| 101 OnWebContentsNavigation(const content::LoadCommittedDetails& details, | 101 OnWebContentsNavigation(content::NavigationHandle* navigation_handle) { |
| 102 const content::FrameNavigateParams& params) { | 102 if (navigation_handle->IsSamePage()) { |
| 103 if (details.is_in_page) { | |
| 104 // Within-page navigations don't change the set of elements that | 103 // Within-page navigations don't change the set of elements that |
| 105 // exist, and we only support filtering on the top-level URL, so | 104 // exist, and we only support filtering on the top-level URL, so |
| 106 // this can't change which rules match. | 105 // this can't change which rules match. |
| 107 return; | 106 return; |
| 108 } | 107 } |
| 109 | 108 |
| 110 // Top-level navigation produces a new document. Initially, the | 109 // Top-level navigation produces a new document. Initially, the |
| 111 // document's empty, so no CSS rules match. The renderer will send | 110 // document's empty, so no CSS rules match. The renderer will send |
| 112 // an ExtensionHostMsg_OnWatchedPageChange later if any CSS rules | 111 // an ExtensionHostMsg_OnWatchedPageChange later if any CSS rules |
| 113 // match. | 112 // match. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 base::Bind(&Delegate::RequestEvaluation, base::Unretained(delegate_)), | 224 base::Bind(&Delegate::RequestEvaluation, base::Unretained(delegate_)), |
| 226 base::Bind(&DeclarativeContentCssConditionTracker:: | 225 base::Bind(&DeclarativeContentCssConditionTracker:: |
| 227 DeletePerWebContentsTracker, | 226 DeletePerWebContentsTracker, |
| 228 base::Unretained(this)))); | 227 base::Unretained(this)))); |
| 229 // Note: the condition is always false until we receive OnWatchedPageChange, | 228 // Note: the condition is always false until we receive OnWatchedPageChange, |
| 230 // so there's no need to evaluate it here. | 229 // so there's no need to evaluate it here. |
| 231 } | 230 } |
| 232 | 231 |
| 233 void DeclarativeContentCssConditionTracker::OnWebContentsNavigation( | 232 void DeclarativeContentCssConditionTracker::OnWebContentsNavigation( |
| 234 content::WebContents* contents, | 233 content::WebContents* contents, |
| 235 const content::LoadCommittedDetails& details, | 234 content::NavigationHandle* navigation_handle) { |
| 236 const content::FrameNavigateParams& params) { | |
| 237 DCHECK(base::ContainsKey(per_web_contents_tracker_, contents)); | 235 DCHECK(base::ContainsKey(per_web_contents_tracker_, contents)); |
| 238 per_web_contents_tracker_[contents]->OnWebContentsNavigation(details, params); | 236 per_web_contents_tracker_[contents]->OnWebContentsNavigation( |
| 237 navigation_handle); |
| 239 } | 238 } |
| 240 | 239 |
| 241 bool DeclarativeContentCssConditionTracker::EvaluatePredicate( | 240 bool DeclarativeContentCssConditionTracker::EvaluatePredicate( |
| 242 const ContentPredicate* predicate, | 241 const ContentPredicate* predicate, |
| 243 content::WebContents* tab) const { | 242 content::WebContents* tab) const { |
| 244 DCHECK_EQ(this, predicate->GetEvaluator()); | 243 DCHECK_EQ(this, predicate->GetEvaluator()); |
| 245 const DeclarativeContentCssPredicate* typed_predicate = | 244 const DeclarativeContentCssPredicate* typed_predicate = |
| 246 static_cast<const DeclarativeContentCssPredicate*>(predicate); | 245 static_cast<const DeclarativeContentCssPredicate*>(predicate); |
| 247 auto loc = per_web_contents_tracker_.find(tab); | 246 auto loc = per_web_contents_tracker_.find(tab); |
| 248 DCHECK(loc != per_web_contents_tracker_.end()); | 247 DCHECK(loc != per_web_contents_tracker_.end()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 301 } |
| 303 } | 302 } |
| 304 | 303 |
| 305 void DeclarativeContentCssConditionTracker::DeletePerWebContentsTracker( | 304 void DeclarativeContentCssConditionTracker::DeletePerWebContentsTracker( |
| 306 content::WebContents* contents) { | 305 content::WebContents* contents) { |
| 307 DCHECK(base::ContainsKey(per_web_contents_tracker_, contents)); | 306 DCHECK(base::ContainsKey(per_web_contents_tracker_, contents)); |
| 308 per_web_contents_tracker_.erase(contents); | 307 per_web_contents_tracker_.erase(contents); |
| 309 } | 308 } |
| 310 | 309 |
| 311 } // namespace extensions | 310 } // namespace extensions |
| OLD | NEW |