Chromium Code Reviews| 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_track_decider.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/WebDataSource.h" | |
| 12 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace page_load_metrics { | |
| 16 | |
| 17 RendererPageTrackDecider::RendererPageTrackDecider( | |
| 18 const blink::WebDocument* document, | |
| 19 const blink::WebDataSource* data_source) | |
| 20 : document_(document), data_source_(data_source) {} | |
| 21 | |
| 22 RendererPageTrackDecider::~RendererPageTrackDecider() {} | |
| 23 | |
| 24 bool RendererPageTrackDecider::HasCommitted() { | |
| 25 // RendererPageTrackDecider is only instantiated for committed pages. TODO | |
| 26 // see if blink exposes a concept of whether the current page is provisional | |
| 27 // or committed. | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 bool RendererPageTrackDecider::IsHTTPOrHTTPSUrl() { | |
| 32 const GURL url = document_->url(); | |
|
Charlie Harrison
2016/09/14 13:20:05
Can this method be just one line?
Bryan McQuade
2016/09/14 15:10:58
Yeah - the reason I did this is a bit silly - WebD
| |
| 33 return url.SchemeIsHTTPOrHTTPS(); | |
| 34 } | |
| 35 | |
| 36 bool RendererPageTrackDecider::IsNewTabPageUrl() { | |
| 37 return SearchBouncer::GetInstance()->IsNewTabPage(document_->url()); | |
| 38 } | |
| 39 | |
| 40 bool RendererPageTrackDecider::IsChromeErrorPage() { | |
| 41 return data_source_->hasUnreachableURL(); | |
| 42 } | |
| 43 | |
| 44 bool RendererPageTrackDecider::IsHTTPErrorPage() { | |
| 45 // 2xx and 3xx (304 not modified) response codes are not error pages. | |
| 46 int status_code_family = data_source_->response().httpStatusCode() / 100; | |
| 47 return status_code_family != 2 && status_code_family != 3; | |
| 48 } | |
| 49 | |
| 50 bool RendererPageTrackDecider::IsHTMLOrXHTMLPage() { | |
| 51 // Ignore non-HTML documents (e.g. SVG). Note that images are treated by | |
| 52 // Blink as HTML documents, so to exclude images, we must perform | |
| 53 // additional mime type checking below. | |
| 54 if (!document_->isHTMLDocument() && !document_->isXHTMLDocument()) | |
| 55 return false; | |
| 56 | |
| 57 // Ignore non-HTML mime types (e.g. images). | |
| 58 std::string mime_type = data_source_->response().mimeType().utf8(); | |
|
Charlie Harrison
2016/09/14 13:20:05
Could you directly compare the WebString without c
Bryan McQuade
2016/09/14 15:10:58
Ah, I think so, yes. The default WebString equalit
| |
| 59 return mime_type == "text/html" || mime_type == "application/xhtml+xml"; | |
| 60 } | |
| 61 | |
| 62 } // namespace page_load_metrics | |
| OLD | NEW |