XWalk WebView patchset, README and LICENSE files.
[platform/framework/web/xwalk_webview.git] / patchset / 0008-Add-reload-button.patch
1 From e8dc8c58037f1c9cfd5678150c77e9113bf8754a Mon Sep 17 00:00:00 2001
2 From: Dongseong Hwang <dongseong.hwang@intel.com>
3 Date: Thu, 4 Jul 2013 15:12:47 +0300
4 Subject: [PATCH 08/33] Add reload button.
5
6 Load url that command line indicates.
7 Add reload button.
8 There are two purposes.
9 1. show how to add API.
10 2. check load correctly, because it is hard to check forward and back button due to lack of url field.
11 ---
12  efl_webview/examples/main.cc | 18 ++++++++++++++++++
13  efl_webview/lib/webview.cc   | 39 +++++++++++++++++++++++++++++++++++++++
14  efl_webview/lib/webview.h    |  3 +++
15  3 files changed, 60 insertions(+)
16
17 diff --git a/efl_webview/examples/main.cc b/efl_webview/examples/main.cc
18 index ee610fb..f69ad43 100644
19 --- a/efl_webview/examples/main.cc
20 +++ b/efl_webview/examples/main.cc
21 @@ -28,6 +28,14 @@ on_forward_button_clicked(void *user_data, Evas_Object *forward_button, void *ev
22    webview->Forward();
23  }
24  
25 +static void
26 +on_reload_button_clicked(void *user_data,
27 +                         Evas_Object *forward_button, void *event_info)
28 +{
29 +  xwalk::WebView* webview = static_cast<xwalk::WebView*>(user_data);
30 +  webview->Reload();
31 +}
32 +
33  static void window_create()
34  {
35    /* Create window */
36 @@ -65,6 +73,14 @@ static void window_create()
37    elm_box_pack_end(horizontal_layout, forward_button);
38    evas_object_show(forward_button);
39  
40 +  /* Create Reload button */
41 +  Evas_Object* reload_button = elm_button_add(elm_window);
42 +  elm_object_text_set(reload_button, "RELOAD");
43 +  evas_object_size_hint_weight_set(reload_button, 0.0, EVAS_HINT_EXPAND);
44 +  evas_object_size_hint_align_set(reload_button, 0.0, 0.5);
45 +  elm_box_pack_end(horizontal_layout, reload_button);
46 +  evas_object_show(reload_button);
47 +
48    /* Create WebView */
49    xwalk::WebView* webview_object = xwalk::WebView::Create(elm_window);
50    Evas_Object* webview = webview_object->EvasObject();
51 @@ -78,6 +94,8 @@ static void window_create()
52                                   on_back_button_clicked, webview_object);
53    evas_object_smart_callback_add(forward_button, "clicked",
54                                   on_forward_button_clicked, webview_object);
55 +  evas_object_smart_callback_add(reload_button, "clicked",
56 +                                 on_reload_button_clicked, webview_object);
57  
58    evas_object_resize(elm_window, window_width, window_height);
59    evas_object_show(elm_window);
60 diff --git a/efl_webview/lib/webview.cc b/efl_webview/lib/webview.cc
61 index 510f452..33b00de 100644
62 --- a/efl_webview/lib/webview.cc
63 +++ b/efl_webview/lib/webview.cc
64 @@ -6,10 +6,13 @@
65  
66  #include <Elementary.h>
67  #include "base/command_line.h"
68 +#include "base/file_util.h"
69 +#include "base/files/file_path.h"
70  #include "content/browser/web_contents/web_contents_view_efl.h"
71  #include "content/public/browser/web_contents.h"
72  #include "content/public/browser/web_contents_delegate.h"
73  #include "efl_webview/lib/web_runtime_context.h"
74 +#include "net/base/net_util.h"
75  
76  namespace xwalk {
77  
78 @@ -44,8 +47,11 @@ struct WebView::Private {
79    Evas_Object* view_box;
80    scoped_refptr<WebRuntimeContext> context;
81    scoped_ptr<WebContentsDelegateXWalk> webContentsDelegate;
82 +  static GURL s_startup_url;
83  };
84  
85 +GURL WebView::Private::s_startup_url = GURL();
86 +
87  // static
88  WebView* WebView::Create(Evas_Object* root_window) {
89    return new WebView(root_window);
90 @@ -54,10 +60,27 @@ WebView* WebView::Create(Evas_Object* root_window) {
91  // static
92  void WebView::CommandLineInit(int argc, char** argv) {
93    CommandLine::Init(argc, argv);
94 +
95 +  CommandLine* command_line = CommandLine::ForCurrentProcess();
96 +  const CommandLine::StringVector& args = command_line->GetArgs();
97 +
98 +  if (args.empty())
99 +    return;
100 +
101 +  GURL url(args[0]);
102 +  if (!(url.is_valid() && url.has_scheme()))
103 +    url = net::FilePathToFileURL(base::FilePath(args[0]));
104 +
105 +  WebView::Private::s_startup_url = GURL(url);
106  }
107  
108  WebView::WebView(Evas_Object* root_window)
109      : private_(new Private) {
110 +  {
111 +    if (!WebView::Private::s_startup_url.is_valid())
112 +      WebView::Private::s_startup_url = GURL("about:blank");
113 +  }
114 +
115    private_->root_window = root_window;
116    private_->context = WebRuntimeContext::current();
117    content::BrowserContext* browser_context =
118 @@ -70,6 +93,8 @@ WebView::WebView(Evas_Object* root_window)
119        private_->webContentsDelegate->WebContents()->GetView();
120    static_cast<content::WebContentsViewEfl*>(content_view)->
121        SetViewContainerBox(private_->view_box);
122 +
123 +  LoadURL(WebView::Private::s_startup_url);
124  }
125  
126  WebView::~WebView() {
127 @@ -84,6 +109,20 @@ void WebView::Back() {
128    private_->webContentsDelegate->WebContents()->GetController().GoBack();
129  }
130  
131 +void WebView::Reload() {
132 +  private_->webContentsDelegate->WebContents()->GetController().Reload(false);
133 +}
134 +
135 +void WebView::LoadURL(const GURL& url) {
136 +  content::NavigationController::LoadURLParams params(url);
137 +  params.transition_type = content::PageTransitionFromInt(
138 +      content::PAGE_TRANSITION_TYPED |
139 +      content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
140 +  private_->webContentsDelegate->WebContents()->
141 +      GetController().LoadURLWithParams(params);
142 +  private_->webContentsDelegate->WebContents()->GetView()->Focus();
143 +}
144 +
145  Evas_Object* WebView::EvasObject() {
146    return private_->view_box;
147  }
148 diff --git a/efl_webview/lib/webview.h b/efl_webview/lib/webview.h
149 index 2d4b352..ca1757e 100644
150 --- a/efl_webview/lib/webview.h
151 +++ b/efl_webview/lib/webview.h
152 @@ -9,6 +9,7 @@
153  
154  #include "base/basictypes.h"
155  #include "base/memory/scoped_ptr.h"
156 +#include "googleurl/src/gurl.h"
157  
158  namespace xwalk {
159  
160 @@ -23,6 +24,8 @@ class EAPI WebView {
161  
162    EAPI void Forward();
163    EAPI void Back();
164 +  EAPI void Reload();
165 +  EAPI void LoadURL(const GURL&);
166  
167   private:
168    explicit WebView(Evas_Object*);
169 -- 
170 1.8.1.2
171