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

Side by Side Diff: chrome/renderer/net/error_cache_load.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_cache_load.h"
6
7 #include "content/public/renderer/render_frame.h"
8 #include "gin/handle.h"
9 #include "gin/object_template_builder.h"
10 #include "third_party/WebKit/public/platform/WebURLRequest.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
12 #include "third_party/WebKit/public/web/WebKit.h"
13
14 gin::WrapperInfo ErrorCacheLoad::kWrapperInfo = {gin::kEmbedderNativeGin};
15
16 // static
17 void ErrorCacheLoad::Install(content::RenderFrame* render_frame,
18 const GURL& page_url) {
19 v8::Isolate* isolate = blink::mainThreadIsolate();
20 v8::HandleScope handle_scope(isolate);
21 v8::Handle<v8::Context> context =
22 render_frame->GetWebFrame()->mainWorldScriptContext();
23 if (context.IsEmpty())
24 return;
25
26 v8::Context::Scope context_scope(context);
27
28 gin::Handle<ErrorCacheLoad> controller =
29 gin::CreateHandle(isolate, new ErrorCacheLoad(render_frame, page_url));
30 v8::Handle<v8::Object> global = context->Global();
31 global->Set(gin::StringToV8(isolate, "errorCacheLoad"), controller.ToV8());
32 }
33
34 bool ErrorCacheLoad::ReloadStaleInstance() {
35 if (!render_frame_)
36 return false;
37
38 blink::WebURLRequest request(page_url_);
39 request.setCachePolicy(blink::WebURLRequest::ReturnCacheDataDontLoad);
40
41 render_frame_->GetWebFrame()->loadRequest(request);
42
43 return true;
44 }
45
46 ErrorCacheLoad::ErrorCacheLoad(content::RenderFrame* render_frame,
47 const GURL& page_url)
48 : RenderFrameObserver(render_frame),
49 render_frame_(render_frame),
50 page_url_(page_url) {}
51
52 ErrorCacheLoad::~ErrorCacheLoad() {}
53
54 gin::ObjectTemplateBuilder ErrorCacheLoad::GetObjectTemplateBuilder(
55 v8::Isolate* isolate) {
56 return gin::Wrappable<ErrorCacheLoad>::GetObjectTemplateBuilder(isolate)
57 .SetMethod("reloadStaleInstance", &ErrorCacheLoad::ReloadStaleInstance);
58 }
59
60 void ErrorCacheLoad::OnDestruct() { render_frame_ = NULL; }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698