OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/page_load_metrics/renderer_page_tracker_predicate.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "chrome/renderer/searchbox/search_bouncer.h" |
| 10 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 namespace page_load_metrics { |
| 15 |
| 16 RendererPageTrackerPredicate::RendererPageTrackerPredicate( |
| 17 const blink::WebDocument* document, |
| 18 const blink::WebURLResponse* url_response) |
| 19 : document_(document), url_response_(url_response) {} |
| 20 |
| 21 RendererPageTrackerPredicate::~RendererPageTrackerPredicate() {} |
| 22 |
| 23 bool RendererPageTrackerPredicate::HasCommitted() { |
| 24 // RendererPageTrackerPredicate is only instantiated for committed pages. TODO |
| 25 // see if blink exposes a concept of whether the current page is provisional |
| 26 // or committed. |
| 27 return true; |
| 28 } |
| 29 |
| 30 bool RendererPageTrackerPredicate::IsHTTPOrHTTPSUrl() { |
| 31 const GURL url = document_->url(); |
| 32 return url.SchemeIsHTTPOrHTTPS(); |
| 33 } |
| 34 |
| 35 bool RendererPageTrackerPredicate::IsNewTabPageUrl() { |
| 36 return SearchBouncer::GetInstance()->IsNewTabPage(document_->url()); |
| 37 } |
| 38 |
| 39 bool RendererPageTrackerPredicate::IsChromeErrorPage() { |
| 40 // TODO figure out if blink or content exposes information to know whether the |
| 41 // current page is a chrome error page. |
| 42 return false; |
| 43 } |
| 44 |
| 45 bool RendererPageTrackerPredicate::IsNetworkErrorPage() { |
| 46 // 2xx and 3xx (304 not modified) response codes are not error pages. |
| 47 int status_code_family = url_response_->httpStatusCode() / 100; |
| 48 return status_code_family != 2 && status_code_family != 3; |
| 49 } |
| 50 |
| 51 bool RendererPageTrackerPredicate::IsHTMLOrXHTMLPage() { |
| 52 // Ignore non-HTML documents (e.g. SVG). Note that images are treated by |
| 53 // Blink as HTML documents, so to exclude images, we must perform |
| 54 // additional mime type checking below. |
| 55 if (!document_->isHTMLDocument() && !document_->isXHTMLDocument()) |
| 56 return false; |
| 57 |
| 58 // Ignore non-HTML mime types (e.g. images). |
| 59 std::string mime_type = url_response_->mimeType().utf8(); |
| 60 return mime_type == "text/html" || mime_type == "application/xhtml+xml"; |
| 61 } |
| 62 |
| 63 } // namespace page_load_metrics |
OLD | NEW |