Merge lp:~abreu-alexandre/oxide/donottrack into lp:~oxide-developers/oxide/oxide.trunk

Proposed by Alexandre Abreu
Status: Merged
Merged at revision: 1159
Proposed branch: lp:~abreu-alexandre/oxide/donottrack
Merge into: lp:~oxide-developers/oxide/oxide.trunk
Diff against target: 438 lines (+212/-1) (has conflicts)
13 files modified
qt/core/browser/oxide_qt_web_context.cc (+24/-0)
qt/core/browser/oxide_qt_web_context.h (+3/-0)
qt/core/glue/oxide_qt_web_context_proxy.h (+3/-0)
qt/quick/api/oxideqquickwebcontext.cc (+19/-0)
qt/quick/api/oxideqquickwebcontext_p.h (+6/-0)
qt/tests/qmltests/api/tst_WebContext_doNotTrack.py (+18/-0)
qt/tests/qmltests/api/tst_WebContext_doNotTrack.qml (+74/-0)
shared/browser/oxide_browser_context.cc (+33/-1)
shared/browser/oxide_browser_context.h (+5/-0)
shared/browser/oxide_browser_context_observer.h (+2/-0)
shared/browser/oxide_network_delegate.cc (+10/-0)
shared/browser/oxide_web_view_contents_helper.cc (+14/-0)
shared/browser/oxide_web_view_contents_helper.h (+1/-0)
Text conflict in qt/core/browser/oxide_qt_web_context.cc
To merge this branch: bzr merge lp:~abreu-alexandre/oxide/donottrack
Reviewer Review Type Date Requested Status
Chris Coulson Approve
Review via email: mp+261766@code.launchpad.net

Commit message

Handle do not track

Description of the change

Handle do not track

To post a comment you must log in.
lp:~abreu-alexandre/oxide/donottrack updated
1126. By Chris Coulson

Bump Chromium rev to 45.0.2427.7

1127. By Chris Coulson

Persist media device permissions for the life of WebContext

1128. By Chris Coulson

Make ContentBrowserClient / ContentRendererClient memebers of ContentMainDelegate like ContentClient already is

1129. By Chris Coulson

Pass the application locale to ui::ResourceBundle::InitSharedInstanceWithLocale. Because we don't build with glib support, it's unable to detect the system locale and depends on a preferred one being passed

1130. By Chris Coulson

Convert UserScriptMaster in to a KeyedService

1131. By Chris Coulson

Create a single TestWebContext in tst_WebView_save_restore_state.qml

1132. By Chris Coulson

Don't allow QObjects to be passed to WebContextDelegateWorker

1133. By Chris Coulson

Add justifications around less-obvious uses of base::Unretained

1134. By Olivier Tilloy

Fix save/restore unit tests.

1135. By Chris Coulson

Bump Chromium rev to 45.0.2431.0

1136. By Chris Coulson

Fix an intermittent test failure

1137. By Chris Coulson

Ensure we have a WebScopedMicrotaskSuppression instance on the stack when we call in to V8

1138. By Chris Coulson

Add a basic editorconfig file - you can get editorconfig plugins for various editors from http://editorconfig.org/. This avoids having to turn on support for modelines, which is disabled in some editors (eg, vim) for security reasons

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks, I've left some comments inline.

Also, the test is missing a few bits:

- It should verify that the default is off.
- It should check that the notify signal is emitted when you toggle it.
- What happens to window.navigator.doNotTrack if you change the setting without reloading the page? Does it update automatically? If it does, then that should be tested.

review: Needs Fixing
lp:~abreu-alexandre/oxide/donottrack updated
1139. By Chris Coulson

Some updates for the content script messaging:
- The payload is no longer converted to a string for the wire - instead, we use base::Value directly.
- As a consequence, on the renderer side, we now use content::V8ValueConverter to convert the payload from v8::Value to base::Value. This means we can get rid of the hacky script we compile for each script context, just to call JSON.stringify.
- On the browser-side, we now convert from base::Value directly to QVariant using a custom converter. There is no longer a dependency on QJsonDocument.
- As a hardening measure, our converter on the browser side protects against excessive recursion that would otherwise exhaust stack space.
- The "args" parameter for script messages is deprecated - use "payload" instead. "args" never really made sense as it implies it's always a list, and is there as a consequence of this API being put together in haste to get unit tests working.
- Message payloads no longer have to be JSON arrays or objects - they can be any primitive that can be represented in JSON.
- The script message dispatcher on the browser side is no longer a BrowserMessageFilter running on the IO thread, but instead a WebContentsObserver. We can do that now since it has an API to expose the source RenderFrameHost.

1140. By Chris Coulson

Use the preferred allow() method for the geolocation permission tests (we still retain one test for the deprecated accept() method though)

1141. By Chris Coulson

Store TestApiHost in TestWebView, keyed by WebFrame

1142. By Chris Coulson

Add TestUtils.waitFor, so that we can stop duplicating the same function for tests that don't use TestWebView

1143. By Chris Coulson

Bump depot_tools to c1ae89ecd635abfea2d94e5b49c7d92f49f28f22

1144. By Chris Coulson

Improve script messaging tests

1145. By Chris Coulson

LP: #1466208

1146. By Chris Coulson

Remove a spurious console.log

1147. By Chris Coulson

Correctly detect when we are running on Mir/Mesa

1148. By Chris Coulson

Assume that the display is already initialized

1149. By Chris Coulson

Bump Chromium rev to 45.0.2438.3

1150. By Chris Coulson

Add WebContext.userAgentOverrides API, which is a replacement for WebContext.userAgentOverrideDelegate. The new API allows applications to provide a list of regular expressions and user agent overrides as opposed to providing a JS worker that we call in to to ask for a user agent string. This allows us to stop relying on synchronous IPC to the browser

1151. By Chris Coulson

We can actually lazyily create UserAgentSettings. RenderProcessInitializer will create it when the first render process starts anyway

1152. By Alexandre Abreu

Fixes

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

All comments have been addressed

Revision history for this message
Chris Coulson (chrisccoulson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qt/core/browser/oxide_qt_web_context.cc'
2--- qt/core/browser/oxide_qt_web_context.cc 2015-07-01 09:56:23 +0000
3+++ qt/core/browser/oxide_qt_web_context.cc 2015-07-02 14:03:46 +0000
4@@ -144,9 +144,15 @@
5 session_cookie_mode(content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES),
6 popup_blocker_enabled(true),
7 devtools_enabled(false),
8+<<<<<<< TREE
9 devtools_port(-1),
10 legacy_user_agent_override_enabled(false) {}
11
12+=======
13+ devtools_port(kDefaultDevtoolsPort),
14+ legacy_user_agent_override_enabled(false),
15+ do_not_track(false) {}
16+>>>>>>> MERGE-SOURCE
17 std::string product;
18 std::string user_agent;
19 base::FilePath data_path;
20@@ -164,6 +170,7 @@
21 std::string default_video_capture_device_id;
22 std::vector<UserAgentSettings::UserAgentOverride> user_agent_overrides;
23 bool legacy_user_agent_override_enabled;
24+ bool do_not_track;
25 };
26
27 class SetCookiesContext : public base::RefCounted<SetCookiesContext> {
28@@ -550,6 +557,7 @@
29
30 context_->SetCookiePolicy(construct_props_->cookie_policy);
31 context_->SetIsPopupBlockerEnabled(construct_props_->popup_blocker_enabled);
32+ context_->SetDoNotTrack(construct_props_->do_not_track);
33
34 MediaCaptureDevicesContext* dc =
35 MediaCaptureDevicesContext::Get(context_.get());
36@@ -1074,5 +1082,21 @@
37 client_->DefaultVideoCaptureDeviceChanged();
38 }
39
40+bool WebContext::doNotTrack() const {
41+ if (IsInitialized()) {
42+ return context_->GetDoNotTrack();
43+ }
44+
45+ return construct_props_->do_not_track;
46+}
47+
48+void WebContext::setDoNotTrack(bool dnt) {
49+ if (IsInitialized()) {
50+ context_->SetDoNotTrack(dnt);
51+ } else {
52+ construct_props_->do_not_track = dnt;
53+ }
54+}
55+
56 } // namespace qt
57 } // namespace oxide
58
59=== modified file 'qt/core/browser/oxide_qt_web_context.h'
60--- qt/core/browser/oxide_qt_web_context.h 2015-06-29 17:52:40 +0000
61+++ qt/core/browser/oxide_qt_web_context.h 2015-07-02 14:03:46 +0000
62@@ -148,6 +148,9 @@
63 void clearTemporarySavedPermissionStatuses() override;
64 void setLegacyUserAgentOverrideEnabled(bool enabled) override;
65
66+ bool doNotTrack() const override;
67+ void setDoNotTrack(bool dnt) override;
68+
69 // oxide::MediaCaptureDevicesContextClient implementation
70 void DefaultAudioDeviceChanged() override;
71 void DefaultVideoDeviceChanged() override;
72
73=== modified file 'qt/core/glue/oxide_qt_web_context_proxy.h'
74--- qt/core/glue/oxide_qt_web_context_proxy.h 2015-07-01 09:56:23 +0000
75+++ qt/core/glue/oxide_qt_web_context_proxy.h 2015-07-02 14:03:46 +0000
76@@ -138,6 +138,9 @@
77 virtual void clearTemporarySavedPermissionStatuses() = 0;
78
79 virtual void setLegacyUserAgentOverrideEnabled(bool enabled) = 0;
80+
81+ virtual bool doNotTrack() const = 0;
82+ virtual void setDoNotTrack(bool dnt) = 0;
83 };
84
85 } // namespace qt
86
87=== modified file 'qt/quick/api/oxideqquickwebcontext.cc'
88--- qt/quick/api/oxideqquickwebcontext.cc 2015-07-01 09:56:23 +0000
89+++ qt/quick/api/oxideqquickwebcontext.cc 2015-07-02 14:03:46 +0000
90@@ -1119,6 +1119,7 @@
91 // if the actual device is removed
92 }
93
94+
95 QVariantList OxideQQuickWebContext::userAgentOverrides() const {
96 Q_D(const OxideQQuickWebContext);
97
98@@ -1133,6 +1134,12 @@
99 return rv;
100 }
101
102+bool OxideQQuickWebContext::doNotTrack() const {
103+ Q_D(const OxideQQuickWebContext);
104+
105+ return d->proxy()->doNotTrack();
106+}
107+
108 void OxideQQuickWebContext::setUserAgentOverrides(
109 const QVariantList& overrides) {
110 Q_D(OxideQQuickWebContext);
111@@ -1160,4 +1167,16 @@
112 emit userAgentOverridesChanged();
113 }
114
115+void OxideQQuickWebContext::setDoNotTrack(bool dnt) {
116+ Q_D(OxideQQuickWebContext);
117+
118+ if (doNotTrack() == dnt) {
119+ return;
120+ }
121+
122+ d->proxy()->setDoNotTrack(dnt);
123+
124+ emit doNotTrackEnabledChanged();
125+}
126+
127 #include "moc_oxideqquickwebcontext_p.cpp"
128
129=== modified file 'qt/quick/api/oxideqquickwebcontext_p.h'
130--- qt/quick/api/oxideqquickwebcontext_p.h 2015-06-29 16:47:46 +0000
131+++ qt/quick/api/oxideqquickwebcontext_p.h 2015-07-02 14:03:46 +0000
132@@ -73,6 +73,8 @@
133
134 Q_PROPERTY(QVariantList userAgentOverrides READ userAgentOverrides WRITE setUserAgentOverrides NOTIFY userAgentOverridesChanged REVISION 3)
135
136+ Q_PROPERTY(bool doNotTrackEnabled READ doNotTrack WRITE setDoNotTrack NOTIFY doNotTrackEnabledChanged REVISION 3)
137+
138 Q_ENUMS(CookiePolicy)
139 Q_ENUMS(SessionCookieMode)
140
141@@ -169,6 +171,9 @@
142 QVariantList userAgentOverrides() const;
143 void setUserAgentOverrides(const QVariantList& overrides);
144
145+ bool doNotTrack() const;
146+ void setDoNotTrack(bool dnt);
147+
148 Q_SIGNALS:
149 void productChanged();
150 void userAgentChanged();
151@@ -191,6 +196,7 @@
152 Q_REVISION(3) void defaultAudioCaptureDeviceIdChanged();
153 Q_REVISION(3) void defaultVideoCaptureDeviceIdChanged();
154 Q_REVISION(3) void userAgentOverridesChanged();
155+ Q_REVISION(3) void doNotTrackEnabledChanged();
156
157 private:
158 Q_PRIVATE_SLOT(d_func(), void userScriptUpdated());
159
160=== added file 'qt/tests/qmltests/api/tst_WebContext_doNotTrack.py'
161--- qt/tests/qmltests/api/tst_WebContext_doNotTrack.py 1970-01-01 00:00:00 +0000
162+++ qt/tests/qmltests/api/tst_WebContext_doNotTrack.py 2015-07-02 14:03:46 +0000
163@@ -0,0 +1,18 @@
164+from cStringIO import StringIO
165+
166+def handler(request):
167+ request.send_response(200)
168+ request.send_header("Content-type", "text/html")
169+
170+ html = StringIO()
171+ for header in request.headers:
172+ print header
173+ html.write(
174+ "<html><body><div id='dnt'>{}</div></body></html>".format(
175+ "1" if 'DNT' in request.headers and request.headers['DNT'] == '1' else "0"))
176+
177+ request.send_header("Content-Length", html.tell())
178+ request.send_header("Cache-Control", "no-cache")
179+ request.end_headers()
180+
181+ request.wfile.write(html.getvalue())
182
183=== added file 'qt/tests/qmltests/api/tst_WebContext_doNotTrack.qml'
184--- qt/tests/qmltests/api/tst_WebContext_doNotTrack.qml 1970-01-01 00:00:00 +0000
185+++ qt/tests/qmltests/api/tst_WebContext_doNotTrack.qml 2015-07-02 14:03:46 +0000
186@@ -0,0 +1,74 @@
187+import QtQuick 2.0
188+import QtTest 1.0
189+import com.canonical.Oxide 1.9
190+import com.canonical.Oxide.Testing 1.0
191+
192+TestWebView {
193+ id: webView
194+
195+ focus: true
196+
197+ width: 200
198+ height: 200
199+
200+ SignalSpy {
201+ id: dntSignalSpy
202+ target: webView.context
203+ signalName: "doNotTrackEnabledChanged"
204+ }
205+
206+ TestCase {
207+ id: test
208+ name: "WebContext_doNotTrack"
209+ when: windowShown
210+
211+ function init() {
212+ dntSignalSpy.clear();
213+ }
214+
215+ function test_dnt_data() {
216+ return [
217+ {expectedHeaderDnt: "0", expectedNavigatorDnt: "0"}, /* default */
218+ {expectedHeaderDnt: "0", expectedNavigatorDnt: "0", dnt: false},
219+ {expectedHeaderDnt: "1", expectedNavigatorDnt: "1", dnt: true}
220+ ]
221+ }
222+
223+ function test_dnt(data) {
224+ if (data.dnt != null) {
225+ webView.context.doNotTrackEnabled = data.dnt
226+ }
227+
228+ webView.url = "http://testsuite/tst_WebContext_doNotTrack.py";
229+ verify(webView.waitForLoadSucceeded(),
230+ "Timed out waiting for successful load");
231+
232+ compare(webView.getTestApi().evaluateCode(
233+ "document.querySelector(\"#dnt\").innerHTML"),
234+ data.expectedHeaderDnt);
235+ compare(webView.getTestApi().evaluateCode(
236+ "window.navigator.doNotTrack && window.navigator.doNotTrack === '1' ? '1' : '0'"),
237+ data.expectedNavigatorDnt);
238+ }
239+
240+ function test_dntNavigatorUpdate(data) {
241+ webView.context.doNotTrackEnabled = false
242+
243+ webView.url = "http://testsuite/tst_WebContext_doNotTrack.py";
244+ verify(webView.waitForLoadSucceeded(),
245+ "Timed out waiting for successful load");
246+
247+ compare(webView.getTestApi().evaluateCode(
248+ "window.navigator.doNotTrack && window.navigator.doNotTrack === '1' ? '1' : '0'"),
249+ "0");
250+
251+ webView.context.doNotTrackEnabled = true;
252+
253+ compare(webView.getTestApi().evaluateCode(
254+ "window.navigator.doNotTrack && window.navigator.doNotTrack === '1' ? '1' : '0'"),
255+ "1");
256+
257+ compare(dntSignalSpy.count, 2, "Should have had 1 doNotTrackEnabledChanged signal");
258+ }
259+ }
260+}
261
262=== modified file 'shared/browser/oxide_browser_context.cc'
263--- shared/browser/oxide_browser_context.cc 2015-07-01 12:25:41 +0000
264+++ shared/browser/oxide_browser_context.cc 2015-07-02 14:03:46 +0000
265@@ -191,7 +191,8 @@
266 session_cookie_mode(params.session_cookie_mode),
267 popup_blocker_enabled(true),
268 host_mapping_rules(params.host_mapping_rules),
269- user_agent_settings(new UserAgentSettingsIOData(context)) {}
270+ user_agent_settings(new UserAgentSettingsIOData(context)),
271+ do_not_track(false) {}
272
273 mutable base::Lock lock;
274
275@@ -207,6 +208,8 @@
276
277 scoped_ptr<UserAgentSettingsIOData> user_agent_settings;
278
279+ bool do_not_track;
280+
281 scoped_refptr<BrowserContextDelegate> delegate;
282 };
283
284@@ -343,6 +346,12 @@
285 return max_cache_size_hint;
286 }
287
288+bool BrowserContextIOData::GetDoNotTrack() const {
289+ const BrowserContextSharedIOData& data = GetSharedData();
290+ base::AutoLock lock(data.lock);
291+ return data.do_not_track;
292+}
293+
294 URLRequestContext* BrowserContextIOData::CreateMainRequestContext(
295 content::ProtocolHandlerMap& protocol_handlers,
296 content::URLRequestInterceptorScopedVector request_interceptors) {
297@@ -869,10 +878,33 @@
298 return io_data()->cookie_store_;
299 }
300
301+
302 TemporarySavedPermissionContext*
303 BrowserContext::GetTemporarySavedPermissionContext() const {
304 DCHECK(CalledOnValidThread());
305 return io_data()->GetTemporarySavedPermissionContext();
306 }
307
308+bool BrowserContext::GetDoNotTrack() const {
309+ DCHECK(CalledOnValidThread());
310+ return io_data()->GetSharedData().do_not_track;
311+}
312+
313+void BrowserContext::SetDoNotTrack(bool dnt) {
314+ DCHECK(CalledOnValidThread());
315+
316+ BrowserContextSharedIOData& data = io_data()->GetSharedData();
317+ base::AutoLock lock(data.lock);
318+ data.do_not_track = dnt;
319+
320+ FOR_EACH_OBSERVER(BrowserContextObserver,
321+ GetOriginalContext()->observers_,
322+ NotifyDoNotTrackChanged());
323+ if (HasOffTheRecordContext()) {
324+ FOR_EACH_OBSERVER(BrowserContextObserver,
325+ GetOffTheRecordContext()->observers_,
326+ NotifyDoNotTrackChanged());
327+ }
328+}
329+
330 } // namespace oxide
331
332=== modified file 'shared/browser/oxide_browser_context.h'
333--- shared/browser/oxide_browser_context.h 2015-07-01 09:56:23 +0000
334+++ shared/browser/oxide_browser_context.h 2015-07-02 14:03:46 +0000
335@@ -84,6 +84,8 @@
336 base::FilePath GetCachePath() const;
337 int GetMaxCacheSizeHint() const;
338
339+ bool GetDoNotTrack() const;
340+
341 virtual bool IsOffTheRecord() const = 0;
342
343 URLRequestContext* CreateMainRequestContext(
344@@ -208,6 +210,9 @@
345
346 const std::vector<std::string>& GetHostMappingRules() const;
347
348+ bool GetDoNotTrack() const;
349+ void SetDoNotTrack(bool dnt);
350+
351 // from content::BrowserContext
352 content::ResourceContext* GetResourceContext() override;
353
354
355=== modified file 'shared/browser/oxide_browser_context_observer.h'
356--- shared/browser/oxide_browser_context_observer.h 2014-06-02 15:06:30 +0000
357+++ shared/browser/oxide_browser_context_observer.h 2015-07-02 14:03:46 +0000
358@@ -30,6 +30,8 @@
359
360 virtual void NotifyPopupBlockerEnabledChanged() {}
361
362+ virtual void NotifyDoNotTrackChanged() {}
363+
364 protected:
365 BrowserContextObserver();
366 BrowserContextObserver(BrowserContext* context);
367
368=== modified file 'shared/browser/oxide_network_delegate.cc'
369--- shared/browser/oxide_network_delegate.cc 2015-06-29 17:14:55 +0000
370+++ shared/browser/oxide_network_delegate.cc 2015-07-02 14:03:46 +0000
371@@ -26,6 +26,10 @@
372
373 namespace oxide {
374
375+namespace {
376+const char kDoNotTrackHeaderName[] = "DNT";
377+}
378+
379 int NetworkDelegate::OnBeforeURLRequest(
380 net::URLRequest* request,
381 const net::CompletionCallback& callback,
382@@ -35,6 +39,12 @@
383 return net::OK;
384 }
385
386+ bool do_not_track = context_->GetDoNotTrack();
387+ if (do_not_track) {
388+ request->SetExtraRequestHeaderByName(
389+ kDoNotTrackHeaderName, "1", true);
390+ }
391+
392 return delegate->OnBeforeURLRequest(request, callback, new_url);
393 }
394
395
396=== modified file 'shared/browser/oxide_web_view_contents_helper.cc'
397--- shared/browser/oxide_web_view_contents_helper.cc 2015-06-03 09:51:37 +0000
398+++ shared/browser/oxide_web_view_contents_helper.cc 2015-07-02 14:03:46 +0000
399@@ -59,6 +59,19 @@
400 UpdateWebPreferences();
401 }
402
403+void WebViewContentsHelper::NotifyDoNotTrackChanged() {
404+ content::RendererPreferences* renderer_prefs =
405+ web_contents_->GetMutableRendererPrefs();
406+ renderer_prefs->enable_do_not_track = context_->GetDoNotTrack();
407+
408+ // Send the new override string to the renderer.
409+ content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
410+ if (!rvh) {
411+ return;
412+ }
413+ rvh->SyncRendererPrefs();
414+}
415+
416 WebViewContentsHelper::WebViewContentsHelper(content::WebContents* contents,
417 content::WebContents* opener)
418 : BrowserContextObserver(
419@@ -73,6 +86,7 @@
420 content::RendererPreferences* renderer_prefs =
421 web_contents_->GetMutableRendererPrefs();
422 renderer_prefs->browser_handles_non_local_top_level_requests = true;
423+ renderer_prefs->enable_do_not_track = context_->GetDoNotTrack();
424
425 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
426 if (rvh) {
427
428=== modified file 'shared/browser/oxide_web_view_contents_helper.h'
429--- shared/browser/oxide_web_view_contents_helper.h 2015-06-03 09:51:37 +0000
430+++ shared/browser/oxide_web_view_contents_helper.h 2015-07-02 14:03:46 +0000
431@@ -62,6 +62,7 @@
432
433 // BrowserContextObserver implementation
434 void NotifyPopupBlockerEnabledChanged() final;
435+ void NotifyDoNotTrackChanged() final;
436
437 // WebPreferencesObserver implementation
438 void WebPreferencesValueChanged() final;

Subscribers

People subscribed via source and target branches