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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 "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.
6
7 #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.
8 #include "chrome/renderer/net/net_error_helper.h"
9 #include "content/public/renderer/render_frame.h"
10 #include "gin/handle.h"
11 #include "gin/object_template_builder.h"
12 #include "third_party/WebKit/public/platform/WebURLRequest.h"
13 #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
14 #include "third_party/WebKit/public/web/WebFrame.h"
15 #include "third_party/WebKit/public/web/WebKit.h"
16
17 gin::WrapperInfo ErrorPageHelperFunctions::kWrapperInfo = {
18 gin::kEmbedderNativeGin};
19
20 // static
21 void ErrorPageHelperFunctions::Install(content::RenderFrame* render_frame,
22 const GURL& page_url) {
23 v8::Isolate* isolate = blink::mainThreadIsolate();
24 v8::HandleScope handle_scope(isolate);
25 v8::Handle<v8::Context> context =
26 render_frame->GetWebFrame()->mainWorldScriptContext();
27 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
28 return;
29
30 v8::Context::Scope context_scope(context);
31
32 gin::Handle<ErrorPageHelperFunctions> controller = gin::CreateHandle(
33 isolate, new ErrorPageHelperFunctions(render_frame, page_url));
34 v8::Handle<v8::Object> global = context->Global();
35 global->Set(gin::StringToV8(isolate, "helperFunctions"), controller.ToV8());
36 }
37
38 bool ErrorPageHelperFunctions::LoadStaleButtonClick() {
39 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
40 return false;
41
42 NetErrorHelper* net_error_helper =
43 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame_);
44 DCHECK(net_error_helper);
45 net_error_helper->LoadStaleButtonPressed();
46
47 return true;
48 }
49
50 bool ErrorPageHelperFunctions::ReloadButtonClick() {
51 if (!render_frame_)
52 return false;
53
54 NetErrorHelper* net_error_helper =
55 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame_);
56 DCHECK(net_error_helper);
57 net_error_helper->ReloadButtonPressed();
58
59 return true;
60 }
61
62 bool ErrorPageHelperFunctions::MoreButtonClick() {
63 if (!render_frame_)
64 return false;
65
66 NetErrorHelper* net_error_helper =
67 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame_);
68 DCHECK(net_error_helper);
69 net_error_helper->MoreButtonPressed();
70
71 return true;
72 }
73
74 ErrorPageHelperFunctions::ErrorPageHelperFunctions(
75 content::RenderFrame* render_frame,
76 const GURL& page_url)
77 : RenderFrameObserver(render_frame),
78 render_frame_(render_frame),
79 page_url_(page_url) {}
80
81 ErrorPageHelperFunctions::~ErrorPageHelperFunctions() {}
82
83 gin::ObjectTemplateBuilder ErrorPageHelperFunctions::GetObjectTemplateBuilder(
84 v8::Isolate* isolate) {
85 return gin::Wrappable<ErrorPageHelperFunctions>::GetObjectTemplateBuilder(
86 isolate)
87 .SetMethod("loadStaleButtonClick",
88 &ErrorPageHelperFunctions::LoadStaleButtonClick)
89 .SetMethod("reloadButtonClick",
90 &ErrorPageHelperFunctions::ReloadButtonClick)
91 .SetMethod("moreButtonClick",
92 &ErrorPageHelperFunctions::MoreButtonClick);
93 }
94
95 void ErrorPageHelperFunctions::OnDestruct() { render_frame_ = NULL; }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698