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 = { | |
15 gin::kEmbedderNativeGin}; | |
16 | |
17 // static | |
18 void ErrorCacheLoad::Install(content::RenderFrame* render_frame, | |
19 const GURL& page_url) { | |
20 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
21 v8::HandleScope handle_scope(isolate); | |
22 v8::Handle<v8::Context> context = | |
23 render_frame->GetWebFrame()->mainWorldScriptContext(); | |
24 if (context.IsEmpty()) | |
25 return; | |
26 | |
27 v8::Context::Scope context_scope(context); | |
28 | |
29 gin::Handle<ErrorCacheLoad> controller = | |
30 gin::CreateHandle(isolate, new ErrorCacheLoad(render_frame, page_url)); | |
31 v8::Handle<v8::Object> global = context->Global(); | |
32 global->Set(gin::StringToV8(isolate, "errorCacheLoad"), controller.ToV8()); | |
33 } | |
34 | |
35 bool ErrorCacheLoad::ReloadStaleInstance() { | |
36 DCHECK(!render_frame_destroyed_); | |
jochen (gone - plz use gerrit)
2014/03/24 12:18:50
the v8 context (and therefore this object) can eas
Randy Smith (Not in Mondays)
2014/03/24 16:19:25
Ok, but for my curiosity, what keeps the V8 contex
| |
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 render_frame_destroyed_(false) {} | |
52 | |
53 ErrorCacheLoad::~ErrorCacheLoad() {} | |
54 | |
55 gin::ObjectTemplateBuilder ErrorCacheLoad::GetObjectTemplateBuilder( | |
56 v8::Isolate* isolate) { | |
57 return gin::Wrappable<ErrorCacheLoad>::GetObjectTemplateBuilder(isolate) | |
58 .SetMethod("reloadStaleInstance", &ErrorCacheLoad::ReloadStaleInstance); | |
59 } | |
60 | |
61 void ErrorCacheLoad::OnDestruct() { | |
62 render_frame_destroyed_ = true; | |
jochen (gone - plz use gerrit)
2014/03/24 12:18:50
just NULL out the render_frame_ instead of adding
Randy Smith (Not in Mondays)
2014/03/24 16:19:25
Done.
| |
63 } | |
OLD | NEW |