Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4755)

Unified Diff: chrome/renderer/net/error_page_helper_functions.cc

Issue 207553008: Surface button for loading stale cache copy on net error page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor tweaks from self-review. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/net/error_page_helper_functions.cc
diff --git a/chrome/renderer/net/error_page_helper_functions.cc b/chrome/renderer/net/error_page_helper_functions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ec47f2ff1cd1753ace47b6ce5b2ad027fd21c57b
--- /dev/null
+++ b/chrome/renderer/net/error_page_helper_functions.cc
@@ -0,0 +1,95 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "error_page_helper_functions.h"
mmenke 2014/04/09 15:59:26 Use full path.
Randy Smith (Not in Mondays) 2014/04/10 21:51:01 Ooops; done.
+
+#include "base/strings/string_util.h"
mmenke 2014/04/09 15:59:26 Is this needed? Or just base/strings/string_piece
Randy Smith (Not in Mondays) 2014/04/10 21:51:01 Done.
+#include "chrome/renderer/net/net_error_helper.h"
+#include "content/public/renderer/render_frame.h"
+#include "gin/handle.h"
+#include "gin/object_template_builder.h"
+#include "third_party/WebKit/public/platform/WebURLRequest.h"
+#include "third_party/WebKit/public/web/WebDataSource.h"
mmenke 2014/04/09 15:59:26 Are either of these two needed?
Randy Smith (Not in Mondays) 2014/04/10 21:51:01 Nope; the refactor into NEHC removed these referen
+#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebKit.h"
+
+gin::WrapperInfo ErrorPageHelperFunctions::kWrapperInfo = {
+ gin::kEmbedderNativeGin};
+
+// static
+void ErrorPageHelperFunctions::Install(content::RenderFrame* render_frame,
+ const GURL& page_url) {
+ v8::Isolate* isolate = blink::mainThreadIsolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::Handle<v8::Context> context =
+ render_frame->GetWebFrame()->mainWorldScriptContext();
+ if (context.IsEmpty())
mmenke 2014/04/09 15:59:26 Can this happen?
Randy Smith (Not in Mondays) 2014/04/10 21:51:01 So this code was cut&pasted from DomAutomationCont
jochen (gone - plz use gerrit) 2014/04/14 13:11:53 If JavaScript is disabled by content settings, thi
+ return;
+
+ v8::Context::Scope context_scope(context);
+
+ gin::Handle<ErrorPageHelperFunctions> controller = gin::CreateHandle(
+ isolate, new ErrorPageHelperFunctions(render_frame, page_url));
+ v8::Handle<v8::Object> global = context->Global();
+ global->Set(gin::StringToV8(isolate, "helperFunctions"), controller.ToV8());
+}
+
+bool ErrorPageHelperFunctions::LoadStaleButtonClick() {
+ if (!render_frame_)
Elly Fong-Jones 2014/04/10 17:15:37 can this object outlive the render_frame_?
Randy Smith (Not in Mondays) 2014/04/10 21:51:01 I'm going based on Jochen's comment in https://cod
jochen (gone - plz use gerrit) 2014/04/14 13:11:53 Right, the javascript wrapper is destroyed via gar
+ return false;
+
+ NetErrorHelper* net_error_helper =
+ content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame_);
+ DCHECK(net_error_helper);
+ net_error_helper->LoadStaleButtonPressed();
+
+ return true;
+}
+
+bool ErrorPageHelperFunctions::ReloadButtonClick() {
+ if (!render_frame_)
+ return false;
+
+ NetErrorHelper* net_error_helper =
+ content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame_);
+ DCHECK(net_error_helper);
+ net_error_helper->ReloadButtonPressed();
+
+ return true;
+}
+
+bool ErrorPageHelperFunctions::MoreButtonClick() {
+ if (!render_frame_)
+ return false;
+
+ NetErrorHelper* net_error_helper =
+ content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame_);
+ DCHECK(net_error_helper);
+ net_error_helper->MoreButtonPressed();
+
+ return true;
+}
+
+ErrorPageHelperFunctions::ErrorPageHelperFunctions(
+ content::RenderFrame* render_frame,
+ const GURL& page_url)
+ : RenderFrameObserver(render_frame),
+ render_frame_(render_frame),
+ page_url_(page_url) {}
+
+ErrorPageHelperFunctions::~ErrorPageHelperFunctions() {}
+
+gin::ObjectTemplateBuilder ErrorPageHelperFunctions::GetObjectTemplateBuilder(
+ v8::Isolate* isolate) {
+ return gin::Wrappable<ErrorPageHelperFunctions>::GetObjectTemplateBuilder(
+ isolate)
+ .SetMethod("loadStaleButtonClick",
+ &ErrorPageHelperFunctions::LoadStaleButtonClick)
+ .SetMethod("reloadButtonClick",
+ &ErrorPageHelperFunctions::ReloadButtonClick)
+ .SetMethod("moreButtonClick",
+ &ErrorPageHelperFunctions::MoreButtonClick);
+}
+
+void ErrorPageHelperFunctions::OnDestruct() { render_frame_ = NULL; }

Powered by Google App Engine
This is Rietveld 408576698