Merge pull request #6482 from deepak1556/webcontents_navigation_obs_patch

webcontents: replace deprecated navigation observers
This commit is contained in:
Cheng Zhao 2016-07-14 12:57:26 +09:00 committed by GitHub
commit ba887dbde7
6 changed files with 34 additions and 55 deletions

View file

@ -47,6 +47,7 @@
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
@ -603,20 +604,6 @@ void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
Emit("did-finish-load");
}
void WebContents::DidFailProvisionalLoad(
content::RenderFrameHost* render_frame_host,
const GURL& url,
int code,
const base::string16& description,
bool was_ignored_by_handler) {
bool is_main_frame = !render_frame_host->GetParent();
Emit("did-fail-provisional-load", code, description, url, is_main_frame);
// Do not emit "did-fail-load" for canceled requests.
if (code != net::ERR_ABORTED)
Emit("did-fail-load", code, description, url, is_main_frame);
}
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
const GURL& url,
int error_code,
@ -660,13 +647,27 @@ void WebContents::DidGetRedirectForResourceRequest(
details.headers.get());
}
void WebContents::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
if (details.is_navigation_to_different_page())
Emit("did-navigate", params.url);
else if (details.is_in_page)
Emit("did-navigate-in-page", params.url);
void WebContents::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
bool is_main_frame = navigation_handle->IsInMainFrame();
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
auto url = navigation_handle->GetURL();
bool is_in_page = navigation_handle->IsSamePage();
if (is_main_frame && !is_in_page) {
Emit("did-navigate", url);
} else if (is_in_page) {
Emit("did-navigate-in-page", url);
}
} else {
auto url = navigation_handle->GetURL();
int code = navigation_handle->GetNetErrorCode();
auto description = net::ErrorToShortString(code);
Emit("did-fail-provisional-load", code, description, url, is_main_frame);
// Do not emit "did-fail-load" for canceled requests.
if (code != net::ERR_ABORTED)
Emit("did-fail-load", code, description, url, is_main_frame);
}
}
void WebContents::TitleWasSet(content::NavigationEntry* entry,

View file

@ -245,11 +245,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
int error_code,
const base::string16& error_description,
bool was_ignored_by_handler) override;
void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description,
bool was_ignored_by_handler) override;
void DidStartLoading() override;
void DidStopLoading() override;
void DidGetResourceResponseStart(
@ -257,9 +252,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
void DidGetRedirectForResourceRequest(
content::RenderFrameHost* render_frame_host,
const content::ResourceRedirectDetails& details) override;
void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
bool OnMessageReceived(const IPC::Message& message) override;
void WebContentsDestroyed() override;
void NavigationEntryCommitted(

View file

@ -7,6 +7,7 @@
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "content/public/browser/guest_host.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
@ -95,10 +96,13 @@ void WebViewGuestDelegate::SetSize(const SetSizeParams& params) {
auto_size_enabled_ = enable_auto_size;
}
void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url, ui::PageTransition transition_type) {
api_web_contents_->Emit("load-commit", url, !render_frame_host->GetParent());
void WebViewGuestDelegate::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
auto is_main_frame = navigation_handle->IsInMainFrame();
auto url = navigation_handle->GetURL();
api_web_contents_->Emit("load-commit", url, is_main_frame);
}
}
void WebViewGuestDelegate::DidAttach(int guest_proxy_routing_id) {

View file

@ -47,9 +47,8 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
protected:
// content::WebContentsObserver:
void DidCommitProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url, ui::PageTransition transition_type) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
// content::BrowserPluginGuestDelegate:
void DidAttach(int guest_proxy_routing_id) final;

View file

@ -20,7 +20,6 @@
#include "atom/renderer/node_array_buffer_bridge.h"
#include "atom/renderer/preferences_manager.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/renderer/media/chrome_key_systems.h"
#include "chrome/renderer/pepper/pepper_helper.h"
#include "chrome/renderer/printing/print_web_view_helper.h"
@ -32,7 +31,6 @@
#include "content/public/renderer/render_view.h"
#include "ipc/ipc_message_macros.h"
#include "native_mate/dictionary.h"
#include "net/base/net_errors.h"
#include "third_party/WebKit/public/web/WebCustomElement.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrameWidget.h"
@ -322,16 +320,4 @@ void AtomRendererClient::AddKeySystems(
AddChromeKeySystems(key_systems);
}
void AtomRendererClient::GetNavigationErrorStrings(
content::RenderFrame* render_frame,
const blink::WebURLRequest& failed_request,
const blink::WebURLError& error,
std::string* error_html,
base::string16* error_description) {
if (!error_description)
return;
*error_description = base::UTF8ToUTF16(net::ErrorToShortString(error.reason));
}
} // namespace atom

View file

@ -58,11 +58,6 @@ class AtomRendererClient : public content::ContentRendererClient {
const std::string& mime_type,
const GURL& original_url) override;
void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
void GetNavigationErrorStrings(content::RenderFrame* render_frame,
const blink::WebURLRequest& failed_request,
const blink::WebURLError& error,
std::string* error_html,
base::string16* error_description) override;
std::unique_ptr<NodeBindings> node_bindings_;
std::unique_ptr<AtomBindings> atom_bindings_;