OLD | NEW |
| (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; } | |
OLD | NEW |